简体   繁体   English

自动保存在 VS 代码中的 Python 中的注释和函数头之间添加两个空行

[英]Auto save adds two empty lines between comment and function header in Python in VS code

I write code in Python in VS code.我在 VS 代码中用 Python 编写代码。 If I add comment before function and hit save button, VS code adds two empty lines:如果我在函数前添加注释并点击保存按钮,VS 代码会添加两个空行:

# comment


def MyMethod():
    return 0

In settings I see that I use autopep8 formatter:在设置中,我看到我使用 autopep8 格式化程序: autopep8 格式化程序

I wasnt able to find what causes this annoying issue.我无法找到导致这个烦人问题的原因。 Maybe I can configure settings somewhere?也许我可以在某处配置设置?

This is due to the code convention (PEP8) of Python.这是由于 Python 的代码约定 (PEP8)。 Pylance will correct your code when saving. Pylance 将在保存时更正您的代码。
This is an excerpt of PEP8 which you can find here :这是 PEP8 的摘录,您可以在这里找到:
You should use two spaces after a sentence-ending period.

If the comment describes your function, try using Docstrings.如果注释描述了您的函数,请尝试使用 Docstrings。

Comment documenting function behavior should be placed inside function, just below signature.注释记录函数行为应放在函数内部,就在签名下方。 If it is not describing function (is placed outside function) it should have those blank lines.如果它没有描述功能(放在功能之外),它应该有那些空行。 Don't mess with language's conventions, it's very bad idea.不要乱用语言的约定,这是非常糟糕的主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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