例如:
def decor(func): def wrap(): print ( "============" ) func() print ( "============" ) return wrap def print_text(): print ( "Hello world!" ) decorated = decor(print_text) decorated() |
结果:
============ Hello world! ============