cognitive science
and more
Fix mixed tab/space indentation in Python code

In Python you can choose whether you want to indent your code using spaces or tabs. However, mixing the two can cause problems. Therefore, I made a simple Python script to fix mixed indentation.

Download: fixindent.

Let's say that you want to change all tab-indents to space-indents (4 spaces wide).

fixindent -i my_input_script.py -s -w 4 -o my_output_script.py

Or, conversely, change all space-indents (8 spaces wide) into tabs. You also want to clean-up extraneous white-space etc. from the line-endings (-c):

fixindent -i my_input_script.py -t -w 8 -c -o my_output_script.py

You can also use pipelines (under Linux at least):

cat my_input_script.py | fixindent -t -c > my_output_script.py