I am a beginner at Python and have made the mistake of mixing spaces and tabs for indentations. I see people use reindent.py
, but I have no idea how to use it. please explain in the simplest way possible without trying to use too fancy words and dumb it down as best as possible as I am a beginner.
Thanks.
If no paths are given on the command line, reindent operates as a filter, reading a single source file from standard input and writing the transformed source to standard output. In this case, the -d , -r and -v flags are ignored. You can pass one or more file and/or directory paths.
It is Ctrl + [ in IDLE. You can change it to your favorite Shift + Tab in Options -> Configure IDLE - Keys.
Just select the text you want indented and hit Tab . To un-indent, select the text and hit Shift + Tab .
For example if you start off using four spaces for an indent, then you should always use four spaces. In the example below, four spaces have been used for the first indent, but only two for the second, and you can see that as a result the code doesn't “line up”. phrase = input("Talk to me > ")
To install reindent with the python package manager, you can first run pip install reindent
on your system. Then simply call from the terminal
reindent -n file.py
The script will modify file.py
.
If you do not want to modify the original file, you can simply run the command without the -n
flag, and you get:
reindent file.py
which will return a file called file.py.bak
, which is the corrected version.
You run reindent.py
like this:
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 want a backup file.
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