Decorator -python

A - formation of decorators, without modifying the basis of the original function newly added function (Advanced closures) - Open Closed Principle

Execution order

Original function (function to be decorated): def func () function decorator def timmer (f): new features, print (end - start)

- syntactic sugar @

On one line of the original function plus decorative function name = @ decorative function call assignment func = timmer (func)

 

- Get the original function's return value

- decorative tape decorative function parameters 1, tacked (with reference wrapper)

 

Guess you like

Origin www.cnblogs.com/tyky-chenji/p/10961059.html