Why property works only for objects?
Chris Mellon
arkanes at gmail.com
Fri Mar 10 12:27:12 EST 2006
On 3/10/06, Michal Kwiatkowski <ruby at no.spam> wrote:
> 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.
The new module will also allow you create entirely new classes (among
other things) at run time, which might be a cleaner way than
monkey-patching in new superclasses.
>
> mk
> --
> . o . >> http://joker.linuxstuff.pl <<
> . . o It's easier to get forgiveness for being wrong
> o o o than forgiveness for being right.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list