.. image:: https://travis-ci.org/myint/pyformat.svg?branch=master :target: https://travis-ci.org/myint/pyformat :alt: Build status
pyformat formats Python code to follow a consistent style.
From pip::
$ pip install --upgrade pyformat
After running::
$ pyformat --in-place example.py
This code:
.. code-block:: python
def launch_rocket ():
"""Launch
the rocket. Go colonize space."""
def factorial(x): '''
Return x factorial.
This uses math.factorial.
'''
import math
import re
import os
return math.factorial( x );
def print_factorial(x): """Print x factorial""" print( factorial(x) ) def main(): """Main function""" print_factorial(5) if factorial(10): launch_rocket()
Gets formatted into this:
.. code-block:: python
def launch_rocket(): """Launch the rocket.
Go colonize space.
"""
def factorial(x): """Return x factorial.
This uses math.factorial.
"""
import math
return math.factorial(x)
def print_factorial(x): """Print x factorial.""" print(factorial(x))
def main(): """Main function.""" print_factorial(5) if factorial(10): launch_rocket()
.. _autoflake: https://github.com/myint/autoflake .. _autopep8: https://github.com/hhatto/autopep8 .. _docformatter: https://github.com/myint/docformatter .. _unify: https://github.com/myint/unify