folgende Klasse verwende ich für x-Koordinaten:
Code: Alles auswählen
class X(object):
def __init__(self, value, max_):
self.value = value
self.max_ = max_
def __call__(self):
return self.value
def __add__(self, other):
if self.value + other <= self.max_:
self.value = self.value + other
else:
self.value = self.max_
return self
Code: Alles auswählen
>>> x = X(0, 5)
>>> x #statt x()
0
>>> x += 3
>>> x #statt x()
3
Gruß
mutetella