Python linter, PEP

I am learning python via freeCodeCamp .
I have a python code that has very long comments in it. I tried some online tools to make my code more standard just with this in mind to break the long comments in different lines. I was not successful. They changed other parts of code but not comments. It seems they just ignore comments and work just on the code.

As a learner, I would like to learn writing better and according to the standard. Reading through PEP8 is really too much for me. Also, if I do not stick to good habits it would be harder in future to make myself correct. When I pass Workshop steps in freeCodeCamp curriculum, I enjoy how it makes the written code standard for the next step. I wanna learn this. So recommend. I saw someone in YT that used flake8 and changed things according to it.
However if I could some help of e.g. VS Code add-on that specially works well on comments too it will be so useful. Then I can focus on coding and meanwhile gradually learn how to type.

Hi @reThinker,

I looked it up. There’s a VS Code extension called Rewrap Revived that should work to break up your long comments into different lines.

Happy coding

Thanks @dhess . I’m glad You are here to help me also here :sweat_smile:
I tested it. Good but not working for comments inline with code (it just works if the whole line is only comment).

Any suggestions for me for writing better and according to PEP?

When you go to the next step in a workshop and the code is standardized by fCC, what type of changes do you usually see?

You could start by tackling just one thing to make your code more readable. For example, it looks like you tend to assign a variable like this:

myVariable=someValue

But it is more readable like this with spaces around the assignment operator:

myVariable = someValue

Also, comments generally are placed on the line above the code you’re commenting about:

#my comment about this code
some code

You might want to consider just using PEP8 as a reference for looking up something you’re interested in knowing more about (i..e. naming conventions) since it has well-structured content links.

There is also a very new VS Code extension (it’s only been out for 6 months and has ~2K+ downloads) called 42 Python Formatter - AutoPEP + Flake8 if you’re feeling experimental.

Hope that helps.

1 Like

@dhess , " 42 Python Formatter ", I tested it and had problems. My vs-code kept showing a window for errors I cannot remember but referenced to not having flake8 or sth like that, while they were installed. Updating VS-code and reopening,… was not useful.

The VS-code default formatter is now acceptable until I’ll be a great programmer who solves this single issue. I already can write a python program to solve this problem :victory_hand:.

Thanks for help. Your guides were useful and obvious.

I think what you’re looking for is a combination of a formatter and a linter.

For Python code, Black is a great place to start. It automatically formats your code according to common Python style conventions, so you don’t have to learn all of PEP 8 at once.

For comments specifically, you could also look at VS Code extensions that help with comment formatting. However, most Python formatters intentionally focus mainly on the actual code and don’t rewrite the content of your comments.

I’d suggest starting with:

  • Black → automatically formats Python code

  • Flake8 → points out style issues and potential problems

  • VS Code + Python/Pylance extensions → gives you feedback while you type

One important thing: you don’t need to read all of PEP 8 before starting. Use these tools as a learning aid. When Flake8 or another tool tells you something is wrong, look up that particular rule and gradually learn the reasoning behind it.

For long comments, I would also try to develop the habit of writing shorter, focused comments rather than trying to make a formatter automatically split every comment. A comment should ideally explain why something is being done, rather than simply describing what the code does.

That way you can focus on learning Python while your tools gradually teach you good formatting habits.

1 Like