adding methods at runtime

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Thu Jan 10 18:44:01 EST 2008


On Thu, 10 Jan 2008 14:55:18 -0800, zslevi at gmail.com wrote:

> Can I access the class attributes from a method added at runtime? (My
> experience says no.)
> I experimented with the following code:
> 
> [Code snipped]
> 
> So it seems to me, if you add a method to an instance, the method will
> not get "self" as parameter.

You are not adding a method but a function.  Take a look at
`types.MethodType()` to create a method from a function, instance, and
class.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list