Adding attribute to object

Jay O'Connor joconnor at cybermesa.com
Thu Dec 4 01:21:00 CET 2003


marco wrote:

>hi
>
>I've got a class "myClass" ... and i CAN'T EXTENDS this class!
>But i can add NEW methods to "myClass", like that :
>
>method = new.instancemethod( myNewMethod , None, myClass)
>myClass.__dict__[method.__name__] = method
>
>i'd like to add NEW attributs to "myClass" ...
>i'm pretty sure it's possible (with "get/set-attr") ... but i don't know how
>to do that
>in fact, i'd like to wrap an newAttribut to an existingAttribut ...
>can anyone drop me 3 lines on how to do that ?
>  
>

I confess I'm thinking that if you are dynamically adding variables (or 
methods)  to a class (not instance variables and methods)  then 
something is odd with your design






More information about the Python-list mailing list