In python 2.5, I have the following code in a module called modtest.py:
def print_method_module(method):
def printer(self):
print self.__module__
return method(self)
return printer
class ModTest():
@print_method_module
def testmethod(self):
pass
if __name__ == "__main__":
ModTest().testmethod()
However, when I run this, it prints out:
__main__
If I create a second file called modtest2.py and run it:
import modtest
if __name__ == "__main__":
modtest.ModTest().testmethod()
This prints out:
modtest
How can I change the decorator to always print out modtest, the name of the module in which the class is defined?