black and flake8¶
TL;DR: black
and flake8
will make your code pretty and readable, automatically.
There are lots of ways to format your code. Whatever you choose, you should format it nicely. Readability is super important for your users. Having beautiful, readable code will make more people want to use it. You might want to just add a linter to your editor (e.g. pylint)
flake8
¶
This tool will enforce a style guide for you. flake8
will throw an error if you run it on a script that doesn't obey your chosen style. You can set up a .flake8
file which specifies the style you want to keep to. This will let you choose, for example, the max line length you would like. flake8
will check through your code and look for errors, like importing a package that you don't use.
You can set up a GitHub action so that flake8 will automatically check the style of any pull requests.
black
¶
This tool will automatically format your Python code, in a very sane way. It will automatically check for the right spaces between variables, push long lines into multiple lines, and will raise an error if you have a missing bracket somewhere. I highly recommend it.
If you use an editor like atom for coding (which I also recommend) you can add an extension to have black
automatically run whenever you save.