if instance exists problem ..

stef mientki stef.mientki at gmail.com
Thu Oct 18 00:39:45 CEST 2007


hello,

I've written a convenience wrapper around ConfigObj (which is a imporved 
ConfigParser).

Now if I use an instance of the base class, I can easily test is the 
instance exists by " if ini:",
like in this example

    ini = None
    if ini:
        print 'ok',type(ini)
    else:
        print 'wrong',type(ini)
    ini = ConfigObj (filename)
    if ini:
        print 'ok',type(ini)
    else:
        print 'wrong',type(ini)

Now if I derive a new class form this:
class inifile (ConfigObj):
    def __init__ (self, filename):
        self.ini = ConfigObj ( filename , list_values = False, 
write_empty_values = True )
        self.ini.newlines = '\r\n'   # not strictly necessary
        self.Section = ''
        self.Modified = False


the test if an instance exists, always returns false.
    ini = inifile (filename)
    if ini:
        print 'ok',type(ini)
    else:
        print 'wrong',type(ini)

Why is that ?
What should I do to the same simple test for existance ?

thanks,
Stef Mientki




More information about the Python-list mailing list