Tuesday, 25 August 2009

Python indentation TABS and Spaces

Today I 'av mainly been thinking about how to clean up source files that contain a mixture of tabs and spaces. This is illegal in Python 3.x.


It has never been a problem for me as I learned that tabs are evil several years before I started programming with Python. However Pmw has several files that contain tabs. This led me to search for help... I was pleased to find that tools already exist in the Python directories.


The first: tabnanny.py checks files for mixtures of tabs and spaces.

The second reindent.py fixes problems.



$ python /sw/lib/python2.5/tabnanny.py -v .
# remove -v for less output

$ python /sw/lib/python2.5/Tools/scripts/reindent.py -d -r -v .
# remove -d to change files

No comments:

Post a Comment