我很高兴看到decorator
python模块(3.0)的最新版本。它看起来比以前的迭代更清晰(例如,语法比以往更加含蓄)。Python装饰3.0和装饰的参数
然而,它似乎对装饰者的糟糕的支持(例如“酸”的语法,以可怕的方式拉伸隐喻),这些装饰者自己接受论证。有没有人有一个很好的例子,你如何干净地使用decorator
3.0?
def substitute_args(fun, arg_sub_dict):
def wrapper(arg):
new_arg = arg_sub_dict.get(arg, arg)
return fun(new_arg)
# some magic happens here to make sure that type signature,
# __name__, __doc__, etc. of wrapper matches fun
return wrapper
装饰家:http://pypi.python.org/pypi/decorator/ – 2009-06-29 20:07:27