获取函数中定义的函数如果我想如下使用装饰:通过装饰
@getFunc('bar')
def foo():
def bar():
print 'bar'
我怎么会做装饰检索名为酒吧内的功能?
def getFunc(str)
def getFunc_inner(func):
def new(*args, **kwargs):
func(*args, **kwargs)
myFunc = ??# Get function named {str} from func
return new
return getFunc_inner
我想一个办法是使用'inspect'和'ast'模块。 –
简短的回答:你不能 – alko
[在Python中如何获取/设置函数(从外部)的局部变量?](http://stackoverflow.com/questions/1360721/how-to-get-get-设置局部变量的函数从外部在python) – alko