For some reason , my code keeps returning a false reply even if the string is in the file. Here's my code:

def check(self):
    self = str(self)
    if self in config_file:
        print ('Account exists')
    if self not in config_file:
        print ('Account doesn\'t exist')
5 Years
Discussion Span
Last Post by Gribouillis

You can use


instead of second if at line 5, otherwise correct, even the whole function seems pointless as it is only

print 'Account' + ('exists' if str(myobj) in config_file else "doesn't exist")

Where myobj is of type of the your class definition. I would at least define only

def check(self):
    return str(self) in self.config

And use that in my checks instead of the in conditions, and the self.config contains the read in string of the config file (if it would be file object you could use it only once as the file pointer would move as side effect of the test)

Do you know about http://docs.python.org/library/configparser.html ?

Edited by pyTony

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.