Python doesn't know class of function ? : class C:def f():pass; l=[f]; print C.l[0].im_class

John Roth newsgroups at jhrothjr.com
Fri Mar 19 11:27:20 EST 2004


"Robert" <k.robert at gmx.de> wrote in message
news:19804fd8.0403190226.4a060ed0 at posting.google.com...
> Python doesn't know the class of a method when container not direct
> class attribute:
>
> >>> class X:
> ... def f():pass
> ... g=f
> ... l=[f]
> ...
> >>> X.g
> <unbound method X.f>
> >>> X.l[0]
> <function f at 0x01A9E1F0>
> >>> X.l[0].im_class
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> AttributeError: 'function' object has no attribute 'im_class'
> >>>
>
>
> why is l[0] a <function>. Any possibility to find the class of this
> beast dynamically?

As Terry said, this is not possible because of the highly
dynamic nature of Python.

If you'd tell us a bit about what you're trying to accomplish
by relating functions to the class where they're defined, we
might be able to suggest some other ways of approaching
the problem.

John Roth
>
> Robert





More information about the Python-list mailing list