Gerard Flanagan wrote: > Hello > > If I have the Vector class below, is there a means by which I can have > the following behaviour > > > >>>>A = Vector(1, 2) >>>>print A > > (1, 2) > >>>>A = 0 >>>>print A > > (0, 0) > > If there is such a means, will it still work with the __slots__ > attribution uncommented?
No, you can't. The reason is that python doesn't have an assignment operator as e.g. C++ has. The "=" just binds the name A to some object - without the object knowing it. What's wrong with class A: def clear(): pass ... A.clear() ? Alternatively, you could try and abuse one of the seldom used in-place operator like __ior__: A |= 0 But I wouldn't recommend that. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list