我一直在尝试做以下事情:
#[...]
def __history_dependent_simulate(self, node, iterations=1,
*args, **kwargs):
"""
For history-dependent simulations only:
""" + self.simulate.__doc___
我在这里试图完成的是为该私有方法提供与该方法的文档相同的文档simulate
,除了简短的介绍。这将使我能够避免复制粘贴,保留更短的文件,并且不必每次都更新两个函数的文档。
但这不起作用。有谁知道原因,或者有没有解决办法?
更好的解决方案可能是使用装饰器,例如:
def add_docs_for(other_func):
def dec(func):
func.__doc__ = other_func.__doc__ + "\n\n" + func.__doc__
return func
return dec
def foo():
"""documentation for foo"""
pass
@add_docs_for(foo)
def bar():
"""additional notes for bar"""
pass
help(bar) # --> "documentation for foo // additional notes for bar"
这样你就可以对文档字符串进行任意操作。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)