Python decorators functools.wraps (func) Comments

    1. functools_wraps explain

      1. example

We use a decorator in user_login_data functools.wraps decorator function for the inner wrapper function into ????????

So this functools_wraps in the end is doing it?

We create a test.py to explain:

Code is as follows: We define a normal function instead and print __name__

After you add a decorator look:

Discovery changed. This we should all remember, after decorator decorative finish, we were decorated name of the function will become a decorator function ??????????????

One more function:

__Name__ maybe find function are changed to the wrapper.

After adding functools.wraps decoration:

Find ways to restore the original name.

 

Guess you like

Origin blog.csdn.net/weixin_44786530/article/details/91458106