stef mientki schrieb:
> 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 ?

Use isinstance(obj, type).

Diez
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to