Why property works only for objects?

Alex Martelli aleaxit at yahoo.com
Fri Mar 10 07:57:19 CET 2006


Michal Kwiatkowski <ruby at no.spam> wrote:

> So another question arise. Is it possible to make function a method (so
> it will receive calling object as first argument)?

Sure, impor types then call types.MethodType:

f = types.MethodType(f, obj, someclass)

(f.__get__ is also fine for Python-coded functions) -- make sure that
someclass is obj's class or some ancestor of it, of course.


Alex





More information about the Python-list mailing list