2024-05-08 03:04:22 发布
网友
我可以提供如下帮助文本:
def my_func(): "help text"
这样help(my_func)将打印help text。你知道吗
help(my_func)
help text
是否可以从全局变量构造帮助字符串?你知道吗
例如:
test = "123" def my_func(): "help text" + test
不会为help(my_func)打印任何内容
您可以重写__doc__属性
__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.
您可以重写
__doc__
属性从PEP-0257:
相关问题 更多 >
编程相关推荐