装饰器:
增加一些额外的功能
# !/usr/bin/env python
# -*- coding: utf-8 -*-
import time
print time.time()
def timer(func):
def wrapper():
start_time = time.time()
func()
stop_time = time.time()
print "运行时间:" + str(stop_time - start_time )
return wrapper
@timer
def i_can_sleep():
time.sleep(3)
print i_can_sleep()