def use_logging(level): def decortor(func): def wrapper(*args, **kwargs): if level=='warn': print('%s is running'% func.__name__) return func(*args) return wrapper return decortor # @use_logging(level='warn') 相当于下面的foo = use_logging(level='warn')(foo) def foo(name='foo'): print('i am %s'% name) foo = use_logging(level='warn')(foo) foo()