Is there way to determine which class a method is bound to?
Victor Ng
crankycoder at gmail.com
Fri Feb 25 10:22:32 EST 2005
No - that doesn't work, im_class gives me the current class - in the
case of inheritance, I'd like to get the super class which provides
'bar'.
I suppose I could walk the __bases__ to find the method using the
search routine outlined in:
http://www.python.org/2.2/descrintro.html
but I was hoping for an automatic way of resolving this.
vic
On Fri, 25 Feb 2005 14:54:34 +0000, Richie Hindle <richie at entrian.com> wrote:
>
> [vic]
> > I'm doing some evil things in Python and I would find it useful to
> > determine which class a method is bound to when I'm given a method
> > pointer.
>
> Here you go:
>
> >>> class Foo:
> ... def bar(self):
> ... pass
> ...
> >>> Foo.bar.im_class
> <class __main__.Foo at 0x008ED720>
> >>> Foo().bar.im_class
> <class __main__.Foo at 0x008ED720>
> >>>
>
> --
> Richie Hindle
> richie at entrian.com
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list