I\'m trying to create an application in Python 3.2 and I use tabs all the time for indentation, but even the editor changes some of them into spaces and then print out \"inc
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
}
I oddly ran into a similar issue with one of my .py files. I simply opened the file in Pycharm and pressed Option
+Command
+L
which correctly formats the file contents in one go.
I suspect I was having trouble because I coded this particular .py file through jupyter labs as opposed to my usual choice of sublime text or Pycharm and therefore ran into some hidden indentation issues many answers here have alluded to
Highligt the indented bits, and then click tabs. They will then become consistent :)
Using the autopep8
command below fixed it for me:
autopep8 -i my_file.py
Documentation for autopep8
linked here.
I use Notepad++ and got this error.
In Notepad++ you will see that both the tab and the four spaces are the same, but when you copy your code to Python IDLE you would see the difference and the line with a tab would have more space before it than the others.
To solve the problem, I just deleted the tab before the line then added four spaces.
Well I had the same problem and I realised that the problem is that I copied code from another python editor to sublime.
I was working with jupyter notebook and then I copied the code into sublime. Apparently when you make specific modifications (like moving code in functions) then indentation gets messy and this is where the problem comes from.
So just stick to one editor. If you do so, then you will be having no problem.