python装饰器精髓代码

#!/usr/bin/env python
#-*- coding:utf-8 -*-
import time
def foo(func):
    def inner():
        print('fs...')
        func()
        print('finally...')
    return inner

@foo   #f1 = foo(f1)==inner
def f1():
    time.sleep(1)
    print('f1....')

f1()

输出结果:

fs...
f1....
finally...
原文地址:https://www.cnblogs.com/shanhua-fu/p/7641400.html