47 Python - decorator recall function basis

      Decorator is an advanced knowledge, less define their own decorator situation. But we will use a third-party package or inside the decorator,

01 function basis

001 Overview

(1) Scenario 1: used to manage and enhance the function of behavior

 

 

Before a function definition, which method can be spoken to the class defined by a static method, or methods @staticmethod called class methods, and thus different from the example method.

 

 

(2) Scenario 2

 

 

Scene: such as adding a number of features for tracking or logging function, or debugging time verify the validity of the test. Including automatic lock acquire or release some threads

 

(3) with a decorator advantage

 

 

Former (4) learning decorator preparations
Function assigned to the variable: function name may pay a variable as a parameter - a reference address, a variable name is the name of the function

 

 

Function as an argument: the function name can be passed as a parameter to another function

 

 

Multiple functions entrusted to function as a unified action

 

 

Guess you like

Origin www.cnblogs.com/yijiexi/p/11165802.html