[Python-ideas] Suggestion: Integrate the script "pindent.py" as standard command for formatting pyhton code

Serge Hulne serge.hulne at gmail.com
Thu May 26 07:29:47 CEST 2011


Suggestion: Integrate the script "pindent.py" as standard command for
formatting pyhton code

Here is the link;
http://svn.python.org/projects/python/trunk/Tools/scripts/pindent.py

Pindent stands for "Pyton indent":

Goal :

   1. It provides bloc delimiters (end of blocks) in the for of comments
   (like "#end if" or "#end for" etc ... )
   2. This allows one to check / restore the indentation of Python code, in
   cases where>
      1. A copy/paste went wrong
      2. The indentation of a Python source got corrupted when the script
      was posted on web page, send via email etc ...
      3. Standardise (fix) sources which happily mix whitespaces and tabs
      4. Make Python code more readable for developers used to end of blocs
      delimiters (Ruby, C, C++, C#,Java, etc ...)

 Basically the idea is the same as the Go language "gofmt" (Go format).

Example:

#-------------------
- Before using pindent:

#!/usr/bin env python

i = 0
for c in "hello world":
    if c == 'l':
        i+=1
        print "number of occurrences of `l` :", i

#------------------
- After using indent:

#!/usr/bin env python

i = 0
for c in "hello world":
    if c == 'l':
        i+=1
        print "number of occurrences of `l` :", i
    # end if
# end for


Serge Hulne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20110526/87b7d73b/attachment.html>


More information about the Python-ideas mailing list