Re: replace mothod for only one object but not for a class

2008-10-15 Thread Bruno Desthuilliers
hofer a écrit : Hi hofer a écrit : 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 ob

Re: replace mothod for only one object but not for a class

2008-10-15 Thread hofer
Hi > > hofer a écrit : > >> 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 t

Re: replace mothod for only one object but not for a class

2008-10-15 Thread hofer
On Oct 14, 7:50 pm, hofer <[EMAIL PROTECTED]> wrote: > 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 overh

Re: replace mothod for only one object but not for a class

2008-10-15 Thread Bruno Desthuilliers
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

Re: replace mothod for only one object but not for a class

2008-10-15 Thread Bruno Desthuilliers
George Sakkis a écrit : (snip) You're right of course; that's what you get with minimal testing ;) Still it works with a small modification, binding self to b as default argument: b.foo = lambda self=b: "modified called on %s" % self Ok, now with a real use case : use a named function instead

Re: replace mothod for only one object but not for a class

2008-10-14 Thread George Sakkis
On Oct 14, 12:28 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > George Sakkis a écrit : > > > > > On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote: > >> 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)

Re: replace mothod for only one object but not for a class

2008-10-14 Thread Bruno Desthuilliers
Christian Heimes a écrit : Bruno Desthuilliers wrote: If the class is a new-style one [1], it just requires invoking the descriptor protocol by yourself to get a bound method, ie: Another note about new style classes: You can NOT overwrite most magic methods (__*__) on the instance. Most magi

Re: replace mothod for only one object but not for a class

2008-10-14 Thread Christian Heimes
Bruno Desthuilliers wrote: If the class is a new-style one [1], it just requires invoking the descriptor protocol by yourself to get a bound method, ie: Another note about new style classes: You can NOT overwrite most magic methods (__*__) on the instance. Most magic methods are only looked up

Re: replace mothod for only one object but not for a class

2008-10-14 Thread Bruno Desthuilliers
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.

Re: replace mothod for only one object but not for a class

2008-10-14 Thread Jason Scheirer
On Oct 14, 11:20 am, George Sakkis <[EMAIL PROTECTED]> wrote: > On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote: > > > > > 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 met

Re: replace mothod for only one object but not for a class

2008-10-14 Thread Bruno Desthuilliers
George Sakkis a écrit : On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote: 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 a

Re: replace mothod for only one object but not for a class

2008-10-14 Thread George Sakkis
On Oct 14, 1:50 pm, hofer <[EMAIL PROTECTED]> wrote: > 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 overh

Re: replace mothod for only one object but not for a class

2008-10-14 Thread Miki
from functools import partial class Point: def __init__(self, x, y): self.x, self.y = x, y def show(self, n): for i in range(n): print "Point: (%s, %s)" % (self.x, self.y) def new_method(obj, func): def method(*args, **kw): return func(obj, *args,

replace mothod for only one object but not for a class

2008-10-14 Thread hofer
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