Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??

Dave Kuhlman dkuhlman at rexx.com
Sun Oct 26 19:51:19 EST 2003


Stephen Horne wrote:

[snip]
> 
> Are there any tools which can intelligently redo the indentation
> in a Python source file? Preferably respecting other formatting
> conventions where practical, though of course I accept that no
> program could replace a programmer with an eye for readability in
> this respect.

If you are on Linux/UNIX or have access to the cygwin tools on MS
Windows, then try:

    unexpand -4 orig.py > tmp.py
    expand -2 tmp.py > dest.py
  
to convert from 4-space indents to 2-space indents, and

    unexpand -2 orig.py > tmp.py
    expand -4 tmp.py > dest.py

to convert from 2-space indents to 4-space indents.

But, it does seem like a lot of trouble to go through just so that
people will look at your code and say "Eewh!  Why didn't s/he read
the style guide?" Or maybe they will smirk and say, "I'll bet s/he
uses an editor in which the Tab key doesn't work, ... something
like Notepad on MS Windows.  I pity the fool."

Also, if you have the Python source distribution, look at
Tools/scripts/untabify.py.  Also, in the string module (in the
standard library) and the string data type, look at the
expandtabs() method.

Except, I don't know what these do with tabs in quoted strings.
The default behavior of unexpand is to convert only
characters at the beginning of each line.  With expand, use the -i
option to convert only initial tabs.

Next, ask yourself the following questions: Why is there no
Tools/scripts/tabify.py?  And, why is there no string.unexpandtabs()
method?  Could there be a conspiracy to take away your right to
use tabs?

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman
dkuhlman at rexx.com




More information about the Python-list mailing list