Bruno Desthuilliers a écrit :
hofer a écrit :
Hi,
I have multiple objects all belonging to the same class
(which I didn't implement and whose code I don't want to modify)
Now I'd like to change one method for one object only (after it has
been created) without adding any overhead
to the call of the other object's methods.
Is this possible?
Yes.
If the class is a new-style one [1], it just requires invoking the
descriptor protocol by yourself to get a bound method, ie:
(snip)
If it's a classic class, you can get by using either new.instancemethod
or types.MethodType:
Either I'm starting to get old or I need some vacations... Manually
invoking function.__get__(obj, type(obj)) also work with classic
classes, of course.
(snip)
--
http://mail.python.org/mailman/listinfo/python-list