2
def foo():
print "I am foo"
def bar1():
print "I am bar1"
def bar2():
print "I am bar2"
def barN():
print "I am barN"
funobjs_in_foo = get_nest_functions(foo)
def get_nest_functions(funobj):
#how to write this function??
如何获取所有嵌套函数对象?我可以通过funobj.func_code.co_consts获取嵌套函数的代码对象。但我还没有找到一种方法来获取嵌套函数的函数对象。如何获取嵌套函数对象?
任何帮助表示赞赏。
检查:http://stackoverflow.com/questions/1095543/get-name-of-calling-functions-module-in-python – Moj 2013-04-26 08:49:22
感谢。检查框架只包含代码对象。有人提出了使用gc从代码对象中获取函数对象的方法。但它不适用于这种嵌套功能场景。 – limi 2013-04-26 08:53:27