introspection: How to find out the class defining a method

Holger Joukl Holger.Joukl at LBBW.de
Thu May 6 10:25:58 EDT 2004


Hi,
introspection works different in python 2.3:

Python 2.3.3 (#12, Feb 19 2004, 11:42:09)
[GCC 2.95.2 19991024 (release)] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo:
...     def do(self):
...             pass
...
>>> class Moo(Foo):
...     pass
...
>>> x=Moo()
>>> x.do.im_class
<class __main__.Moo at 0x1a9030>
>>>

whereas:

Python 2.1 (#3, Jun  1 2001, 15:51:25)
[GCC 2.95.2 19991024 (release)] on sunos5
Type "copyright", "credits" or "license" for more information.
>>> class Foo:
...     def do(self):
...             pass
...
>>> class Moo(Foo):
...     pass
...
>>> x=Moo()
>>> x.do.im_class
<class __main__.Foo at cd7b4>
>>>

Is there an elegant way to achieve the latter result (i.e. the base class
in which
this method actually is defined) in python 2.3, too? Couldn´t find it in
the docs.

Cheers
  Holger

Der Inhalt dieser E-Mail ist vertraulich. Falls Sie nicht der angegebene
Empfänger sind oder falls diese E-Mail irrtümlich an Sie adressiert wurde,
verständigen Sie bitte den Absender sofort und löschen Sie die E-Mail
sodann. Das unerlaubte Kopieren sowie die unbefugte Übermittlung sind nicht
gestattet. Die Sicherheit von Übermittlungen per E-Mail kann nicht
garantiert werden. Falls Sie eine Bestätigung wünschen, fordern Sie bitte
den Inhalt der E-Mail als Hardcopy an.

The contents of this  e-mail are confidential. If you are not the named
addressee or if this transmission has been addressed to you in error,
please notify the sender immediately and then delete this e-mail.  Any
unauthorized copying and transmission is forbidden. E-Mail transmission
cannot be guaranteed to be secure. If verification is required, please
request a hard copy version.





More information about the Python-list mailing list