1.装饰器-打印method打印时间的简短装饰器:
import datetime from functools import wraps def runTimeFunc_args(args): def func_wrapper(func): @wraps(func) def return_wrapper(*callvarargs, **callkeywords): starttime = datetime.datetime.now() func_result = func(*callvarargs, **callkeywords) endtime = datetime.datetime.now() print "method:%s runTimesTotal: %f s" % (args,(endtime - starttime).seconds) return func_result return return_wrapper return func_wrapper