<div class="gmail_quote">On Mon, Jan 3, 2011 at 7:47 PM, Alex Hall <span dir="ltr"><<a href="mailto:mehgcap@gmail.com">mehgcap@gmail.com</a>></span> wrote:</div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hi all,<br>
I have a solitaire game in which I use a "Pile" class. This class is<br>
meant to hold a bunch of cards, so I subclass it for the deck, the ace<br>
stacks, and the seven main stacks, defining rules and methods for each<br>
but also relying on the parent Pile class's methods and attributes.<br>
However, I keep getting an error that an attribute in the parent does<br>
not exist in the child. Below is a simplified example, but it gives me<br>
the exact same error: child object has no attribute l.<br>
<br>
class parent(object):<br>
def __init__(self, l=None):<br>
if l is None: l=[]<br>
<br>
class child(parent):<br>
def __init__(self, *args, **kwords):<br>
super(parent, self).__init__(*args, **kwords)<br>
</blockquote><div><br></div><div>I believe you need to pass the object both to super() and to the method itself, as in:</div><div><br></div><div>super(parent, self).__init__(self, *args, **kwords)</div><div><br></div><div>
See the example at <a href="http://docs.python.org/library/functions.html?highlight=super#super">http://docs.python.org/library/functions.html?highlight=super#super</a></div><div><br></div><div>HTH,</div><div><br></div><div>
Vern </div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> self.l.append(5)<br>
<br>
c=child()<br>
print c.l<br>
<br>
Again, I get an error saying that 'child' object has no attribute 'l'.<br>
Python 2.7 on win7x64. Thanks.<br>
<font color="#888888"><br>
--<br>
Have a great day,<br>
Alex (msg sent from GMail website)<br>
<a href="mailto:mehgcap@gmail.com">mehgcap@gmail.com</a>; <a href="http://www.facebook.com/mehgcap" target="_blank">http://www.facebook.com/mehgcap</a><br>
_______________________________________________<br>
Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
To unsubscribe or change subscription options:<br>
<a href="http://mail.python.org/mailman/listinfo/tutor" target="_blank">http://mail.python.org/mailman/listinfo/tutor</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Vern Ceder<br><a href="mailto:vceder@gmail.com" target="_blank">vceder@gmail.com</a>, <a href="mailto:vceder@dogsinmotion.com" target="_blank">vceder@dogsinmotion.com</a><br>
The Quick Python Book, 2nd Ed - <a href="http://bit.ly/bRsWDW" target="_blank">http://bit.ly/bRsWDW</a><br><br><br>