关于python __doc__ docstring

mlz*_*boy 4 python docstring doc

我想显示我的函数的文档字符串,但如果我使用这样的

@cost_time
def func():
    "define ...."
    blabla
print func.__doc__
Run Code Online (Sandbox Code Playgroud)

它不会显示docstring,只是因为我使用一些元编程技巧,如何解决这个问题?

And*_*Dog 12

cost_time装饰器返回的包装函数必须具有docstring而不是func.因此,使用functools.wraps哪个正确设置__name____doc__:

from functools import wraps

def cost_time(fn):
    @wraps(fn)
    def wrapper():
        return fn()

    return wrapper
Run Code Online (Sandbox Code Playgroud)