views:

920

answers:

3

I was wondering if there exists a sort of Python beautifier like the gnu-indent command line tool for C code. Of course indentation is not the point in Python since it is programmer's responsibility but I wish to get my code written in a perfectly homogenous way, taking care particularly of having always identical blank space between operands or after and before separators and between blocks.

+1  A: 

PyLint has some formatting checks.

Vinko Vrsalovic
+1  A: 

Have you looked at pindent?

Andrew Hare
+5  A: 

I am the one who asks the question. In fact, the tool the closest to my needs seems to be PythonTidy (it's a Python program of course : Python is best served by himself ;) ).

candide
Thanks, I'm using PythonTidy now thanks to this, and it's proving useful. It uses the proper mechanism - i.e. the compiler.ast module to parse source into an AST, then walks the AST nodes getting them to write themselves out according to user-defined rules. The code is also very clear, so understanding and modifying its workings to suit my particular standards did not present much difficulty. Though I guess you'd expect clear code from someone who cares deeply enough about formatting to write an automated tool! 10/10