HOWTO: use reindent.py for dummies

I start in Python and made a mistake in mixing spaces and tabs for indentations. I see that people use reindent.py , but I have no idea how to use it. please explain in the simplest way, without trying to use too bizarre words and as deep as possible as I start.

Thanks.

+6
source share
3 answers

To install reindent using the python package manager, you can first run pip install reindent on your system. Then just call from the terminal

 reindent -n file.py 

script will change file.py

If you do not want to modify the source file, you can simply run the command without the -n flag and you will get:

 reindent file.py 

which will return a file called file.py.bak , which is a patched version.

+7
source

You run reindent.py as follows:

 reindent.py <filename>.py 

This will create <filename>.py.bak in the current directory.

If you prefer, you can run it like this: reindent.py -n <filename>.py if you don't need a backup file.

+3
source

If you use the Eclipse IDE, there are two formatting options that you can use to achieve this, accessed from the Source menu. a) " Source> Convert spaces to bookmarks or b)" Source> Convert tabs to spaces I was able to format the code that had 2 spaces instead of the tab using the first option. You simply specify the number of spaces that need to be converted to a tab.

0
source

Source: https://habr.com/ru/post/978434/


All Articles