【发布时间】:2014-01-09 10:27:03
【问题描述】:
这是我需要的:
def get_invoker():
# your magic here
# invoker.py
def f():
invoker = get_invoker()
print(invoker)
# module1.py
class C(object):
def invoke_f(self):
f()
f()
# print <module1>
c = C()
c.invoke_f()
# print C.invoke_f
有可能吗?我知道模块 inspect 拥有所有这些魔力,但我一直没能找到它。
编辑:
我想获取函数对象(或模块)。不仅仅是名字。
【问题讨论】:
-
在最后一个例子中,输出不应该是
invoke_f? -
是的!谢谢@xndrme。
标签: python reflection introspection