def docstring_decorator(s):
"""动态修改docstring装饰器"""
def _decorator(obj):
obj.__doc__ = str(s)
return obj
return _decorator
例子
a = "test"
@docstring_decorator(f"a={a}")
def f():
pass
print(f.__doc__) # a=test
def docstring_decorator(s):
"""动态修改docstring装饰器"""
def _decorator(obj):
obj.__doc__ = str(s)
return obj
return _decorator
例子
a = "test"
@docstring_decorator(f"a={a}")
def f():
pass
print(f.__doc__) # a=test
本文标题:【Python】通过装饰器实现 docstring 中使用变量
本文链接:https://www.haomeiwen.com/subject/jzvfartx.html
网友评论