Is there an official way to add methods to an instance?

Bruno Desthuilliers bruno.42.desthuilliers at websiteburo.invalid
Fri Apr 4 07:26:00 EDT 2008


Paul Rubin a écrit :
> Brian Vanderburg II <BrianVanderburg2 at aim.com> writes:
>> I've checked out some ways to get this to work.  I want to be able to
>> add a new function to an instance of an object.  
> 
> Ugh.  Avoid that if you can.

Why so ? OO is about objects, not classes, and adding methods on a 
per-object basis is perfectly legitimate.

>  But see:
> 
>   http://en.wikipedia.org/wiki/Monkey_patch

Adding methods on a per-object basis is not monkey patching (as defined 
in the above article and as usually understood here) and doesn't address 
the same class (no pun intended) of problems.



More information about the Python-list mailing list