Getting the module name from a method...

Stephen J. Turner sjturner at ix.netcom.com
Tue Aug 17 13:15:41 EDT 1999


Olivier Deckmyn wrote:
> I would like a method of my own to be able to print the module it is
> declared in:
> 
> ex:
> the text for the module : toto.py is :
> 
> class MyClass:
>     def myMethod(self):
>         print "I am in module", ????????
> 
> and then
> MyClass().myMethod()
> should produce :
> 'toto'

How about "self.__class__.__module__"?

Regards,
Stephen

--
Stephen J. Turner <sjturner at ix.netcom.com>




More information about the Python-list mailing list