[英]Get passing argument at python decorator
def deco_test(func):
def inner_function(*args, **kwargs):
return func(*args, **kwargs)
return inner_function
@deco_test
def a(a='asdf', b='asdf'):
pass
if __name__ == '__main__':
a(456, 789)
a(123, b='qwer/123/a.txt')
a(a='098', b='789456')
我想得到这样的论点:
在deco_test(func)
你将不能访问你提供的参数a
内部deco_test
。 修饰是在声明函数时完成的,在调用函数之前,那时您没有关于这些参数的信息。
在inner_function
内部,您得到修饰函数调用a(456, 789)
inner_function
中提供的参数a(456, 789)
将为您args=(456, 789)
。 如果要根据a
可以接受的参数来格式化它们,我认为您必须检查函数a
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.