修飾器模式齿拂,可以對一個函數(shù)驳规、類添加一層封裝。
def decorator_name(f):
def wrap(*args, **kwargs):
print(f.__name__)
print(args)
print(kwargs)
f(*args, **kwargs)
return wrap
@decorator_name
def test_func(arg_1, kwarg=None):
print("in func: ", arg_1, kwarg)
def main():
test_func("one", kwarg="kw_one")
if __name__ == '__main__':
main()