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.
+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
2009-10-01 09:55:50
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
2010-03-01 17:49:46