简体   繁体   中英

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

I write code in Python in VS code. If I add comment before function and hit save button, VS code adds two empty lines:

# comment


def MyMethod():
    return 0

In settings I see that I use autopep8 formatter: 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. Pylance will correct your code when saving.
This is an excerpt of PEP8 which you can find here :
You should use two spaces after a sentence-ending period.

If the comment describes your function, try using 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.

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