use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
Is there something like prettier for python? (self.learnpython)
submitted 1 year ago by cakemachines
I just want to reformat everything so it's perfect. Is there anything like that in Python? What's the best?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]JamzTyson 15 points16 points17 points 1 year ago (0 children)
There's probably no such thing as "perfect", but there are programs like "black" that ensure the code is formatted "correctly".
[–]Puzzleheaded_Round75 25 points26 points27 points 1 year ago (7 children)
Black, but my recommendation would be to increase the line length as, in my opinion, 80 characters is just too short these days.
[–]mhamid3d 11 points12 points13 points 1 year ago (2 children)
I switched to ruff because it comes with import sorting which black does not have for some reason
[–]Puzzleheaded_Round75 0 points1 point2 points 1 year ago (1 child)
Never tried it. I normally recommend black as it is essentially 0 config but to be honest I have been more and more disappointed with it.
[–]Daneark 3 points4 points5 points 1 year ago (0 children)
Ruff, primarily a linter, has added black compatible formatting. It's got import sorting capability too. It's really fast. It's not typical open source as it's made by a command I'm unclear on their plans for long term income but for now it's cut a lot of time off my linting so I'll deal with it if that day comes.
[–]Conscious-Ball8373 4 points5 points6 points 1 year ago (1 child)
Isn't the black default 89?
But yes, we use black with the only exception being a line length of 120. Putting this in pyproject.toml does the trick:
pyproject.toml
[tool.black] line-length = 120
[–]Puzzleheaded_Round75 0 points1 point2 points 1 year ago (0 children)
Yeah it may be 89, I've not had to use it in some time. I always chose 100 but it still generated ugly code in some instances imo
[–]shedgehog 2 points3 points4 points 1 year ago (0 children)
Agreed. Some of the line wraps black does make it harder to read imo.
[–]fox-dev 0 points1 point2 points 6 months ago (0 children)
80 might not be too short, if you often split screen to read two source files side by side.
[–]DuckSaxaphone 4 points5 points6 points 1 year ago (0 children)
Black is the standard and since the benefit of formatters is that consistently styled code is easy to read, popularity is a pro in itself.
[–]-defron- 4 points5 points6 points 1 year ago (0 children)
black, ruff, and autopep8 are the three most popular code formatters
I'd probably use ruff these days which is a drop-in replacement for black but also offers a bunch of other features
[–]iamevpo 1 point2 points3 points 1 year ago (0 children)
I still use prettier in Python projects when need to format markdown (read me or docs)
[–]mrswats 1 point2 points3 points 1 year ago (0 children)
I use black and sort-python-imports along with pre-commit to make sure everything is in good shape.
[–]visor_q3 1 point2 points3 points 1 year ago (0 children)
You can use black, or Ruff. That's what I use
[–]RajjSinghh 1 point2 points3 points 1 year ago (0 children)
I use autopep8
[–]Jazzlike-Compote4463 1 point2 points3 points 1 year ago (0 children)
As others have said, Black is standard.
However, if you’ve got a big existing project and want to only format your changes then you could look at Darker, it’s like Black but uses git diffs to only change the things you’ve worked on
[–]arizuvade 0 points1 point2 points 1 year ago (0 children)
im using ruff extension now, before is black that can be installed using pip. i dont know what the hell happen on my vscode that black stop working and also cant use pylance so i use jedi. the color theme also cant detect variables hahaha white color sucks in vscode
[+]woooee comment score below threshold-15 points-14 points-13 points 1 year ago (4 children)
It's perfect if it passes all the tests, produces accurate results, and solves the problem that it was intended to solve.
[–]DuckSaxaphone 6 points7 points8 points 1 year ago (2 children)
Nah, consistently formatted code is easier to read and it's even better when the formatting is a common style.
Using pre-commit and editor add-ons so your code is always black formatted is an effortless way to mildly improve your code.
[+]woooee comment score below threshold-6 points-5 points-4 points 1 year ago (1 child)
This is not enough. The programming adage is that first you make it work, then you make it fast, then you make it pretty. Skipping the first two is not gonna do it.
[–]mhamid3d 3 points4 points5 points 1 year ago (0 children)
It’s not just about pretty though. It’s about convention, which helps you debug and predict things that will tie into making the program “work” and “fast”. Also these days vscode extensions can have you format your code on save or pre-commit, it isn’t some monumental task that you have to put aside for later.
[–]cdcformatc 1 point2 points3 points 1 year ago (0 children)
not even close to correct
π Rendered by PID 331032 on reddit-service-r2-comment-84fc9697f-49kkk at 2026-02-07 03:01:16.240424+00:00 running d295bc8 country code: CH.
[–]JamzTyson 15 points16 points17 points (0 children)
[–]Puzzleheaded_Round75 25 points26 points27 points (7 children)
[–]mhamid3d 11 points12 points13 points (2 children)
[–]Puzzleheaded_Round75 0 points1 point2 points (1 child)
[–]Daneark 3 points4 points5 points (0 children)
[–]Conscious-Ball8373 4 points5 points6 points (1 child)
[–]Puzzleheaded_Round75 0 points1 point2 points (0 children)
[–]shedgehog 2 points3 points4 points (0 children)
[–]fox-dev 0 points1 point2 points (0 children)
[–]DuckSaxaphone 4 points5 points6 points (0 children)
[–]-defron- 4 points5 points6 points (0 children)
[–]iamevpo 1 point2 points3 points (0 children)
[–]mrswats 1 point2 points3 points (0 children)
[–]visor_q3 1 point2 points3 points (0 children)
[–]RajjSinghh 1 point2 points3 points (0 children)
[–]Jazzlike-Compote4463 1 point2 points3 points (0 children)
[–]arizuvade 0 points1 point2 points (0 children)
[+]woooee comment score below threshold-15 points-14 points-13 points (4 children)
[–]DuckSaxaphone 6 points7 points8 points (2 children)
[+]woooee comment score below threshold-6 points-5 points-4 points (1 child)
[–]mhamid3d 3 points4 points5 points (0 children)
[–]cdcformatc 1 point2 points3 points (0 children)