[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Name self not defined



Jake b wrote:

> On Tue, Jan 27, 2009 at 9:18 PM, Yanom Mobis <yanom@xxxxxxxxxxxxxx> wrote:
> 
> > this is the code in question:
> >
> > class Car(Basicsprite): #car class
> >    def __init__(self, speedarg=(0,0)):
> >        self.speed = speedarg
> >        Basicsprite.__init__(self)
> >
> 
> Is this valid to call parent constructor after other statements? ( Think
> this is invalid in other languages  -- just not sure about python )

Yes. You can call the parents __init__() anywhere in the overridden method.
But... __init__() is not the constructor in the traditional sense (as I
understand it), it is already passed the constructed instance. In python
the constructor is the __new__() method which is passed the class and you
must call the superclass' __new__() to get the instance to work with.

-- 

John Eikenberry
[jae@xxxxxxxx - http://zhar.net]
[PGP public key @ http://zhar.net/jae_at_zhar_net.gpg]
______________________________________________________________
"Perfection is attained, not when no more can be added, but when no more can be
removed." -- Antoine de Saint-Exupery

Attachment: signature.asc
Description: Digital signature