我很高興看到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