我可以提供这样的帮助文本:
def my_func():
"help text"
help(my_func) 将打印帮助文本。
是否可以从全局变量构造帮助字符串?
例如这个:
test = "123"
def my_func():
"help text" + test
不会为 help(my_func) 打印任何内容
请您参考如下方法:
你可以覆盖__doc__属性
test = "123"
def my_func():
pass
my_func.__doc__ = "help text" + test
来自 PEP-0257 :
A docstring is a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the
__doc__special attribute of that object.
