作为一名 Perl 开发人员,我知道 perldoc 实用程序。我是 python 新手,我一直在寻找相同的内容并找到了pydoc。 但 pydoc 的问题是它也在执行我的脚本,而我只想看到写在三引号内的文档。 任何帮助将不胜感激。
最佳答案
可能最好的方法是使用 Python(而不是命令行)。我们以模块sys
为例。首先导入模块,然后使用 help()
,如下所示:
import sys
help(sys)
如果您想查看文档字符串:
print(sys.__doc__)
对于您自己开发的模块,您可以构建一个守卫,以便该模块不被执行,如 documentation 中所述。 :
Note: In order to find objects and their documentation, pydoc imports the module(s) to be documented. Therefore, any code on module level will be executed on that occasion. Use an
if __name__ == '__main__':
guard to only execute code when a file is invoked as a script and not just imported.
关于python - 如何使用 pydoc 仅查看文档文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51924925/