如何在python中以字符串形式检索完整的docstring(调用help()时的内容)

2024-06-28 19:27:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道你可以做something.__doc___甚至inspect.getdoc(something)。但是,我希望以字符串形式检索完整的help()显示。换句话说,当你做help(something)的时候,整个事情都会发生。注意inspect.getdoc(inspect)如何检索显示内容的一小部分,而不是在解释器中检索内容的一小部分。这可能吗


Tags: 字符串内容dochelp事情解释器something形式
1条回答
网友
1楼 · 发布于 2024-06-28 19:27:03

根据this guide,定义docstring应该使help()函数可以使用它。我自己也测试过,它确实有效

我使用的docstring格式(指南也碰巧使用)如下所示:

"""
This is a description of the function
:param name_of_param: what the parameter is for
:return: what the function returns
"""

相关问题 更多 >