简体   繁体   中英

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: 将鼠标悬停在 vs 代码中的 tempfile 模块上

When I try writing something similar at the top of the file I'm importing, the docstring doesn't show up.

Trying this: 尝试在我正在导入的文件中写入文档字符串

But getting this (with no docstring showing): 将鼠标悬停在我尝试导入的 .py 文件上

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'). You can use pydocstyle linter also. It says, for example, that "One-line docstring should fit on one line with quotes". The linter is supported by Python VS Code extension. But be sure, that python.linting.pydocstyleEnabled option is enabled and pydocstyle is installed itself. You can install it globally or locally for your virtual environment. I prefer the global installation - pip install pydocstyle . Also the extension checks, whether all enabled linters are installed and can help to install them.

Re: Solved

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'. 文档字符串工作 The docstring from importing a file must not directly update when changed

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM