replace mothod for only one object but not for a class
Bruno Desthuilliers
bruno.42.desthuilliers at websiteburo.invalid
Wed Oct 15 04:45:35 EDT 2008
More information about the Python-list mailing list
Wed Oct 15 04:45:35 EDT 2008
- Previous message (by thread): replace mothod for only one object but not for a class
- Next message (by thread): replace mothod for only one object but not for a class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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)
- Previous message (by thread): replace mothod for only one object but not for a class
- Next message (by thread): replace mothod for only one object but not for a class
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list