decorator

#Decorator
1. Create a closure (final version)
2. @xx decorates the function you want to decorate #Universal
decorator
def set_fun(func):
def call_fun(*args,**kwargs):
return func(*args ,**kwargs)
return call_fun @set_fun def test(): pass #The decorator adds additional functions to the original function without changing the original function code (principle) #The decorator will not change the original function Parameters and results #The function before decoration (test), which is pointed to by func #The function after decoration (test), which points to call_fun #Closure 1. Nesting of two functions, the outer function returns a reference to the inner function, External functions must have parameters 2. External parameters can be stored in memory, the difference from functions def External function (data): def Internal function (): pass




















return inner function


Decorator ::https://github.com/xianhu/LearnPython/compare/master...dw19970215:patch-3

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324823915&siteId=291194637