Solution:
Fix your editor to use 4 spaces for indentation.
Create a search and replace to replace all tabs with 4 spaces.
Ensure that your editor is set to display tabs as 8 spaces.
Note: The cause for 8 spaces for tabs is so that you instantly notice at the time tabs have been inserted unconsciously - such as at the time copying and pasting from example code that exercise tabs instead of spaces.
Employing the autopep8
command below fixed it for me:
autopep8 -i my_file.py
Documentation for autopep8
linked here.
With the IDLE editor you can exercise this:
Menu Edit → Select All
Menu Format → Untabify Region
Considering your editor has replaced 8 spaces with a tab, enter 8 into the input box.
Press select, and it fixes the entire document.
In case you are employing Sublime Text for Python development, you can eliminate the error by exercising the package Anaconda. Afterwards installing Anaconda, open your file in Sublime Text, right click on the open spaces → Select Anaconda → click on autoformat. Done. Or hit Ctrl + Alt + R.
Usually, people set up indenting with space. It's more compatible across editors, resulting in several mismatches of this sort. But, you are approved to indent with tab. It's your option; but, you must be aware that the standard of 8 spaces per tab is a bit wide.
Involving your problem, most likely, your editor messed up. To alter tab to space is actually editor-dependent.
On Emacs, you can call the method 'untabify'.
On command line, you can exercise a sed line (accommodate the number of spaces to whatever pleases you):
sed -e 's;\t; ;' < yourFile.py > yourNedFile.py
What I did at the time the similar error popped up: choose everything (Str + A) and hit Shift + Tab. So nothing was requistioned anymore. Currently go back to the lines you want to have requistioned, and put it back how you want it.
I currently had the similar problem and traced out that I only required to alter the .py file's charset to UTF-8 as that's the set Python 3 uses.
In Sublime Text, WHILE editing a Python file:
Sublime Text menu > Preferences > Settings - Syntax Specific :
Python.sublime-settings
{
"tab_size": 4,
"translate_tabs_to_spaces": true
}
At the time exercising the sublime text editor, I was able to choose the segment of my code that was giving me the inconsistent use of tabs and spaces in indentation
error and choose:
view > indentation > convert indentation to spaces