I have some tab formatted code in python and I have some space formatted code in python.
Integrating the code in a pain... my editor wants to work in tabs or spaces, but not both.
Is there a command line function in linux or, well, anything which will convert python code formatting one way or the other?
reindent.py is a nifty utility script which converts any python .py file into one using 4-space indents and no tabs.
This is useful for "normalizing" code from disparate sources, assuming you're willing to settle on the 4-space standard. (Or, if you want tabs, you could run reindent.py followed by the unix unexpand
command.)
PS. Your installation of Python may have reindent.py already installed in a Tools or Examples folder. On Ubuntu it is provided by the python-examples
package, and is located at /usr/share/doc/python2.6/examples/Tools/scripts/reindent.py
.
'man expand' for some info
it's in coreutils on Debian
You can use expand and unexpand Unix commands for this.
Generally if I code in vim for instance I have it automatically convert tabs to spaces.
my ~/.vimrc looks something like this:
set expandtab
set tabstop=4
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