Re: Adding functions to an existing instance

2008-06-27 Thread Bruno Desthuilliers
Allen a écrit : [EMAIL PROTECTED] wrote: On 26 juin, 17:18, Allen <[EMAIL PROTECTED]> wrote: I need a way to add a method to an existing instance, but be as close as possible to normal instance methods. def set_method(obj, func, name=None): if not name: name = func.__name__ setattr(ob

Re: Adding functions to an existing instance

2008-06-26 Thread Allen
[EMAIL PROTECTED] wrote: On 26 juin, 17:18, Allen <[EMAIL PROTECTED]> wrote: I need a way to add a method to an existing instance, but be as close as possible to normal instance methods. def set_method(obj, func, name=None): if not name: name = func.__name__ setattr(obj, name, func.__g

Re: Adding functions to an existing instance

2008-06-26 Thread [EMAIL PROTECTED]
On 26 juin, 17:18, Allen <[EMAIL PROTECTED]> wrote: > I need a way to add a method to an existing instance, but be as close as > possible to normal instance methods. def set_method(obj, func, name=None): if not name: name = func.__name__ setattr(obj, name, func.__get__(obj, type(obj))) cl

Adding functions to an existing instance

2008-06-26 Thread Allen
I need a way to add a method to an existing instance, but be as close as possible to normal instance methods. Using 'new' module or such code as 'def addfunc(...): def helper(...) .. setattr(...)' causes a cyclic reference which requires using 'gc.collect' to release the object. Also 'new' is