-1
我想将值列表传递给装饰器。装饰器装饰的每个函数都会传递不同的值列表。我现在用的是decorator
Python库将参数传递给装饰器
这里是我试图 -
from decorator import decorator
def dec(func, *args):
// Do something with the *args - I guess *args contains the arguments
return func()
dec = decorator(dec)
@dec(['first_name', 'last_name'])
def my_function_1():
// Do whatever needs to be done
@dec(['email', 'zip'])
def my_function_2():
// Do whatever needs to be done
但是,这是行不通的。它给出了一个错误 - AttributeError: 'list' object has no attribute 'func_globals'
我该怎么做?
https://stackoverflow.com/questions/5929107/python-decorators-with-parameters – 2014-09-23 14:09:17