confused with class inheritance

Aldo Cortesi aldo at nullcube.com
Sat Sep 14 23:38:33 EDT 2002


Thus spake Rob Hall (bloke at ii.net):

> In a sample app, I have the following:
> 
> >>> class a(sgmllib):
>  pass
> 
> >>> a
> <module '?' (built-in)>
> >>> dir(a)
> []
> >>> dir(sgmllib)
> ['SGMLParseError', 'SGMLParser', 'TestSGMLParser', '__all__',
> '__builtins__', '__doc__', '__file__', '__name__', 'attrfind', 'charref',
> 'commentclose', 'endbracket', 'entityref', 'incomplete', 'interesting',
> 'markupbase', 'piclose', 're', 'shorttag', 'shorttagopen', 'starttagopen',
> 'tagfind', 'test']
> >>> b=a
> >>> dir(b)
> []
> >>>
> 
> Why doesn't dir(b) show the same as dir(sgmllib) ?

sgmllib is a module, not a class. If you try to instantiate
your "class" a, you will get an exception. 


This should act the way you expect it to:

class Foo:
    def oink(self):
        pass

class Bar(Foo):
    pass

print dir(Foo)
print dir(Bar)



Cheers,



Aldo


-- 
Aldo Cortesi
aldo at nullcube.com
http://www.nullcube.com




More information about the Python-list mailing list