[英]Docstring not showing up when importing .py file as a module?
I am working on a project and I am beginning to write functions in other.py files and importing them to the main.py... I want to write help text for the entire file ( module ) that I am importing, similar to when importing a library ( module ) like this:我正在做一个项目,我开始在 other.py 文件中编写函数并将它们导入到 main.py... 我想为我正在导入的整个文件(模块)编写帮助文本,类似于何时像这样导入库(模块):
When I try writing something similar at the top of the file I'm importing, the docstring doesn't show up.当我尝试在要导入的文件顶部编写类似的内容时,文档字符串不会显示。
But getting this (with no docstring showing):但是得到这个(没有显示文档字符串):
It is because of your docstring format probably.这可能是因为您的文档字符串格式。 Try to use such formatting:
尝试使用这样的格式:
"""Helpful docstring for a .py file of functions."""
Then, if VS Code still doesn't show a docstring when a module hovering, use Reload Window command after saving your file (ie Ctrl+Shift+P
and enter 'reload window').然后,如果 VS Code 在模块悬停时仍然不显示文档字符串,请在保存文件后使用Reload Window命令(即
Ctrl+Shift+P
并输入“重新加载窗口”)。 You can use pydocstyle linter also.你也可以使用pydocstyle linter 。 It says, for example, that "One-line docstring should fit on one line with quotes".
例如,它说“单行文档字符串应该适合带引号的一行”。 The linter is supported by Python VS Code extension.
Python VS 代码扩展支持 linter。 But be sure, that
python.linting.pydocstyleEnabled
option is enabled and pydocstyle is installed itself.但可以肯定的是,
python.linting.pydocstyleEnabled
选项已启用,并且pydocstyle已自行安装。 You can install it globally or locally for your virtual environment.您可以为您的虚拟环境全局或本地安装它。 I prefer the global installation -
pip install pydocstyle
.我更喜欢全局安装 -
pip install pydocstyle
。 Also the extension checks, whether all enabled linters are installed and can help to install them.扩展程序还检查是否安装了所有启用的 linter 并可以帮助安装它们。
As suggested in the comments both ' ' and " " are equivalent.正如评论中所建议的那样,“”和“”都是等价的。 The problem had to do with reloading the window as suggested with
Ctrl+Shift+P
and 'reload window'.问题与使用
Ctrl+Shift+P
和“重新加载窗口”的建议重新加载 window 有关。 The docstring from importing a file must not directly update when changed
导入文件的文档字符串在更改时不得直接更新
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.