Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tool to automatically format python code? [closed]

Tags:

python

vim

So when writing C/C++, I get to use the wonderful Clangformat tool, allowing me to write a loooong line and hit a keyboard shortcut to easily and elegantly format my line according to a sane style guide.

Is there an equivalent tool for python? Bonus points if it has a vim plugin.

like image 557
alexgolec Avatar asked Feb 23 '14 03:02

alexgolec


People also ask

What is autopep8 formatter?

autopep8 automatically formats Python code to conform to the PEP 8 style guide. It uses the pycodestyle utility to determine what parts of the code needs to be formatted. autopep8 is capable of fixing most of the formatting issues that can be reported by pycodestyle.

Does prettier work with Python?

Prettier does not work with Python And don't forget to install and select the actual formatter that you want (just like in the official docs).


1 Answers

autopep8:

  • https://github.com/hhatto/autopep8
  • https://pypi.python.org/pypi/autopep8/

A tool that automatically formats Python code to conform to the PEP 8 style guide

To use:

pip install --upgrade autopep8
autopep8 --in-place --aggressive --aggressive <filename>
like image 115
iljau Avatar answered Sep 22 '22 00:09

iljau