Skip to content
forked from myint/pyformat

Formats Python code to follow a consistent style

Notifications You must be signed in to change notification settings

askurihin/pyformat

 
 

Repository files navigation

pyformat

Build status

pyformat formats Python code to follow a consistent style.

Features

  • Formats code to follow the PEP 8 style guide (using autopep8).
  • Removes unused imports (using autoflake).
  • Formats docstrings to follow PEP 257 (using docformatter).
  • Makes strings all use the same type of quote where possible (using unify).

Installation

From pip:

$ pip install --upgrade pyformat

Example

After running:

$ pyformat --in-place example.py

This code:

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:

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()

About

Formats Python code to follow a consistent style

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 98.3%
  • Makefile 1.7%