在Python中将参数和变量从装饰器传递到函数
我是装饰师的新手,如果这看起来很明显,我很抱歉 我有一个叫Test_decorator的装饰师。从参数1和2,它将输出一个列表在Python中将参数和变量从装饰器传递到函数,python,python-3.x,decorator,python-decorators,Python,Python 3.x,Decorator,Python Decorators,我是装饰师的新手,如果这看起来很明显,我很抱歉 我有一个叫Test_decorator的装饰师。从参数1和2,它将输出一个列表 def Test_Decorator(argument1, argument2): def Test(AnotherFunc): def Wrapper(*args, **kwargs): """ Do stuff with argument1 and 2 Output List
def Test_Decorator(argument1, argument2):
def Test(AnotherFunc):
def Wrapper(*args, **kwargs):
"""
Do stuff with argument1 and 2
Output List
"""
List=["List", "Here"]
return AnotherFunc(*args, **kwargs)
return Wrapper
return Test
现在,我想在Func2上使用那个装饰器
这个函数应该使用decorator的列表、decorator的2个参数和2个新参数(参数3和4)
问题是Func2不能使用argument1、argument2和List。我被困在这里了,有人能帮我吗
谢谢为什么不将
List1
传递给AnotherFunc(*args,**kwargs)
?类似于另一个函数(List1=List1,argument3=argument1,argument4=argument2)
但我不能这样做,因为argument1和2与argument3和4不同
@Test_Decorator(argument1, argument2)
def Func2(List, argument3, argument4):
for i in List:
"""
Do stuff with argument 1 to 4 and with List
"""