Contact Python also has a large half of the time, also carried out a lot of Python related development work, but the understanding of Python is still not deep enough, the current knowledge point is only limited to the basic knowledge commonly used, for more in-depth content are not seriously studied and studied, Recently there is a task to add the log function in the original development process, mastering the adorner technology is very helpful to accomplish this task.
Because before contacting Python is mainly in the knowledge of the front end, for JavaScript knowledge of more, after the knowledge of the adorner before the search, know that python in the adorner and the closure of JavaScript is similar to the wonderful, is to include another function in one function, but there is a big difference in the use of these two parts.
The basic syntax format for adorners is:
Def deco (): def wrapper (): print ' AA ' return wrapper@decodef myfunc (): print ' BB ' MyFunc ()
In the above code, for the use of the adorner directly using its syntactic sugar form @, so the benefits of writing is obvious, in the subsequent invocation of the time without repeating the function name, but only with the @ instead. A common perception in Python is that everything is objects, so functions are objects. Here the @ symbol can be understood as Myfunc=deco (MyFunc), MyFunc () shorthand.
The advantage of using adorners is that they can be decorated directly with the @ symbol when the decoration function has been written, so as to add new functions without changing the original code.
Python Decorator Initial Solution