Why property works only for objects?

Michal Kwiatkowski ruby at no.spam
Fri Mar 10 18:18:18 CET 2006


Alex Martelli napisał(a):
>> 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.

I wasn't aware of types module. Thanks for your reply.

mk
-- 
 . o .       >>  http://joker.linuxstuff.pl  <<
 . . o   It's easier to get forgiveness for being wrong
 o o o   than forgiveness for being right.



More information about the Python-list mailing list