defTraet (CHARACTER_TRAET):#Pass the module to be executed from here defInner (*args, * *Kwargs): Character_traet (*args, **kwargs)#invoke the appropriate function returnInner#when the user calls treat, only the memory address of the inner is returned, and the next time it is added (), the inner function is executed .@traetdefNurse (NAI):Print("Treatment Form Nurse%s"%nai) @traetdefMonk ():Print("treatment from Monk")defArcher ():Print("This is a archer the can not treat") Monk () Nurse ("Nainai")#here is equivalent to nurse = traet (nurse) nurse ("Nainai") you're here to replace the nurse function.#results: Treatment from Monk#treatment Form Nurse Nainai
Adorners, as described in order to decorate other functions (adding new functionality), are also functions.
A principle of "open-closed" principle in software development, in simple terms, it stipulates that the function code that has been implemented is not allowed to be modified, but can be extended. The decorator was sent at this time.
Python Basics-adorners