Anomaly in creating class methods

Alex Martelli aleax at mail.comcast.net
Fri Nov 4 00:34:22 EST 2005


venk <venkatasubramanian at gmail.com> wrote:

> Hi,
>  given below is my interaction with the interpreter.... In one case, i
> have created the class method using the "famous idiom"... and in the
> other, i have tried to create it outside the class definition... why
> isn't the latter working ? (of course, the presence of decorators is a
> different issue)....

When you access D.f, you get an unbound method; if you want the
underlying function instead, use D.f.im_func.  When you access f within
the class's body, you do get the underlying function -- that's all of
the difference that's biting you...


Alex



More information about the Python-list mailing list