#!/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...