“`”

用于修复装饰器

<pre><code>mport functools

def deco(func):
@functools.wraps(func) # 加在最内层函数正上方
def wrapper(*args, **kwargs):
return func(*args, **kwargs)

return wrapper

@deco
def index():
'''哈哈哈哈'''
x = 10
print('from index')

print(index.__name__)
print(index.__doc__)

# 加@functools.wraps
# index
# 哈哈哈哈

# 不加@functools.wraps
# wrapper
# None
</code></pre>

 

<pre><code> "“`

Was this helpful?

0 / 0

发表回复 0

Your email address will not be published.