获取Python中调用函数模块的__name__
假设myapp/foo.py
包含:
def info(msg):
caller_name = ????
print '[%s] %s' % (caller_name, msg)
而myapp/bar.py
包含:
import foo
foo.info('Hello') # => [myapp.bar] Hello
我希望在这种情况下,caller_name
被设置为调用函数模块的__name__
属性(即'myapp.foo')。如何实现这个目标?