skip to navigation
skip to content

PythonTidy 1.15

Cleans up, regularizes, and reformats the text of Python scripts.

Latest Version: 1.22

This script reads Python code from standard input and writes a revised version to standard output.

Alternatively, it may be invoked with file names as arguments:

python input output

Suffice it to say that input defaults to ‘-‘, the standard input, and output defaults to ‘-‘, the standard output.

It means to encapsulate the wisdom revealed in:

o Rossum, Guido van, and Barry Warsaw. “PEP 8: Style Guide for Python Code.” 23 Mar. 2006. 28 Nov. 2006 <>.

Python scripts are usually so good looking that no beautification is required. However, from time to time, it may be necessary to alter the style to conform to changing standards. This script converts programs in a consistent way. It abstracts the pretty presentation of the symbolic code from the humdrum process of writing it and getting it to work.

This script assumes that the input Python code is well-formed and works to begin with. It doesn’t check. If all goes well, the output Python code will work, too. Of course, you are advised to test it fully to be sure.

This script should be run only by python.2.5 (and perhaps higher) on scripts written for that version (and perhaps lower) because of its limited knowledge of and expectations for the abstract syntax tree node classes returned by the compiler module. It wouldn’t hurt much to try it from (and on) other versions, though, and it might actually work.

Search this script for “Python Version Dependency.”

Most of the Python 2.5 test suite passes through unimpaired. Here are some tests that dont:

The more esoteric capabilities of had to be turned off to avoid corrupting the test-suite code. In practice, you’ll want to run with PERSONAL = True to use all the functionality, and of course you’ll have the good taste to find and patch all the glitches it introduces.