[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] When to use a constant
swt schreef:
> class Thingy:
> def __init__(self, Position):
> self.Position = Position
> def __getattr__(self, Name):
> if Name=="X":
> return self.Position[0]
> elif Name=="Y":
> return self.Position[1]
> else:
> return self.__dict__[Name]
> def __setattr__(self, Name, Value):
> if Name=="X":
> self.Position[0] = Value
> elif Name=="Y":
> self.Position[1] = Value
> else:
> self.__dict__[Name] = Value
Note that you can do this with properties. Something like (untested):
def getx(self): return self.position[0]
def gety(self): return self.position[1]
def setx(self, v): self.position[0] = v
def sety(self, v): self.position[1] = v
X = property(getx, setx, None, "X position")
Y = property(gety, sety, None, "Y position")
Gerrit.
--
Weather in Twenthe, Netherlands 11/05 15:25:
15.0°C Few clouds mostly cloudy wind 6.3 m/s WNW (57 m above NAP)
--
Ervaringen met het Syndroom van Asperger:
http://topjaklont.student.utwente.nl
Socialistische Partij:
http://www.sp.nl/