Python doesn't know class of function ? : class C:def f():pass; l=[f]; print C.l.im_class
newsgroups at jhrothjr.com
Fri Mar 19 17:27:20 CET 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
> <function f at 0x01A9E1F0>
> >>> X.l.im_class
> Traceback (most recent call last):
> File "<interactive input>", line 1, in ?
> AttributeError: 'function' object has no attribute 'im_class'
> why is l 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
More information about the Python-list