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

Re: [pygame] Name self not defined



On Tue, Jan 27, 2009 at 07:24:13PM -0800, James Paige wrote:
> You can't use "self" in the "def" line. Here is how I usually accomplish 
> what you are trying to do:
> 
> class Car(Basicsprite): #car class
>     def __init__(self, speedarg=(0,0)):
>         self.speed = speedarg
>         Basicsprite.__init__(self)
>     def move(self, speedv=None):
>         if speedv==None: speedv = self.speedv
>         self.rect = self.rect.move(speedv)
> 
> 
> But maybe somebody else can suggest a nicer way to do that.

The idiomatic way to express that is 'if speedv is None:'.
See http://www.python.org/dev/peps/pep-0008/

Marius Gedminas
-- 
lg_PC.gigacharset (lg = little green men language, PC = proxima centauri)
	-- Markus Kuhn provides an example of a locale

Attachment: signature.asc
Description: Digital signature