[Tutor] subclass not inheriting attributes?
Walter Prins
wprins at gmail.com
Tue Jan 4 02:20:17 CET 2011
Sorry, my last post was too hasty. You also had a problem calling super.
It should be like this:
class parent(object):
def __init__(self, l=None):
if l is None: self.l=[]
else: self.l=l
class child(parent):
def __init__(self, *args, **kwords):
super(child, self).__init__(*args, **kwords)
self.l.append(5)
c=child()
print c.l
Basically: In Python 2.x "super()" doesn't know what the current class is.
You have to tell it, as the first parameter. If you tell it a lie, strange
things will happen. That's basically what you did. You called
super(parent,...) instead of super(child,...)
Have a good 2011... ;)
Walter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110104/f1457366/attachment.html>
More information about the Tutor
mailing list