From: Jonathan B. <jbr...@ea...> - 2004-08-18 03:06:26
|
On Tue, 2004-08-17 at 15:11, gp...@ri... wrote: > Should I expect that "+=" will not increment a vector? It should work (and does, as far as I can tell) partially because visual.vector provides the __iadd__() "special member function". Worst case, event if a visual.vector only provided __add__(), the interpreter would synthesize the expression "x += y" as "x = x + y". Python floats are manipulated in this way. Consider this toy example: >>> class fwrap(object): ... def __init__(self): ... self.x = 1.0 ... def get(self): ... return self.x ... def __add__(self, other): ... return self.x + other ... >>> f = fwrap() >>> f.get() 1.0 >>> f + 1.0 2.0 >>> f += 1.0 >>> f.get() Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: 'float' object has no attribute 'get' >>> f 2.0 HTH, -Jonathan |