Getting the module name from a method...
andrew at starmedia.net
Tue Aug 17 20:21:47 CEST 1999
Olivier Deckmyn wrote:
> Hi !
> I would like a method of my own to be able to print the module it is
> declared in:
> the text for the module : toto.py is :
> class MyClass:
> def myMethod(self):
> print "I am in module", ????????
> and then
> should produce :
> Thanx for your help !
> Olivier Deckmyn, Paris - France
> "Any sufficiently advanced technology is indistinguishable from
> magic." -Arthur C. Clark
the name of the current module is __name__
so if you have a module foo.py
and the main executable:
will print 'foo'
"Programmers are just machines that convert coffee to executable code"
"Drew Csillag" <drew_csillag at geocities.com>
More information about the Python-list