Possible Duplicate:
Tool to convert python indentation from spaces to tabs?
I have a number of python files (>1000) that need to be reformatted so indentation is done only with tabs (yes, i know PEP-8, but this is a coding standard of a company). What is the easiest way to do so? Maybe some script in Python that will os.walk
over files and do some magic? I can't just grep
file content since file can be malformed (mixed tab and spaces, different amount of spaces) but Python will still run it and i get it back working after conversion.
I would suggest using this Reindent script on PyPI to convert all of your horribly inconsistent files to a consistent PEP-8 (4-space indents) version.
At this point try one more time to convince whoever decided on tabs that the company coding standard is stupid and PEP-8 style should be used, if this fails then you could use sed (as in hc_'s answer) or create a Python script to replace 4 spaces with a single tab at the beginning of every line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With