将参数和变量从装饰器传递到Python中的函数

时间:2018-07-18 18:12:25

标签: 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
          """

           List=["List", "Here"]

           return AnotherFunc(*args, **kwargs)

      return Wrapper

  return Test

现在,我想在Func2上使用该装饰器。

该函数应该使用装饰器中的列表,装饰器中的2个参数以及2个新参数(参数3和4)。

@Test_Decorator(argument1, argument2)
def Func2(List, argument3, argument4):

   for i in List:
       """
       Do stuff with argument 1 to 4 and with List
       """

问题在于Func2无法使用arguments1,argument2和List。我被困在这里,有人可以帮我吗?

谢谢

0 个答案:

没有答案