我可以提供这样的帮助文本:
def my_func():
"help text"
这样help(my_func)
将打印help text
。
是否可以从全局变量构造帮助字符串?
例如:
test = "123"
def my_func():
"help text" + test
不会为qazxsw poi打印任何东西
您可以覆盖help(my_func)
属性
__doc__
来自test = "123"
def my_func():
pass
my_func.__doc__ = "help text" + test
:
docstring是一个字符串文字,作为模块,函数,类或方法定义中的第一个语句出现。这样的文档字符串成为该对象的PEP-0257特殊属性。