The fourth week - the first 08 chapters -Python3.5- decorator

PCJ # 
# Definition: essentially a function (other decorative function) is to add some additional features for other functions.
Higher-order functions nested functions # + = decorator
# principles: 1. modification function can not be decorated.
# 2, you can not modify the way to call the decorated function.
Time Import
DEF bar (): #bar original code is
the time.sleep (. 3)
Print ( "The bar in")

DEF Timer (FUNC):
DEF Doce ():
START_TIME the time.time = ()
FUNC ()
stop_time = Time .time ()
Print ( "Time >> the FUNC RUN:% S:"% (stop_time-START_TIME))
return Doce

bar = Timer (bar)
bar ()
# passed to the additional function go bar
# original function is to bar printing in the bar adds the ability to print a running time now

Guess you like

Origin www.cnblogs.com/pcjbk/p/10990804.html