You have to edit the script from your home PC, through the hoster's internal editor, through the editor on the smartphone ... Sometimes this error pops up. Fix it in one place, get out in another. Although the entire script indents rework. Perhaps experienced pythonists have a trick to deal with this error?

  • 2
    Always use spaces only. - mkkik
  • Of course, only four spaces. But still somehow manage to appear tabs. - Skotinin
  • If the editor does auto-indent, then tab override must be configured for spaces. Where else can the tabulation itself come from? - mkkik
  • 2
    in your case, only go to 1 space in the form of indentation, it will not be according to standards, but you will immediately see when the tabulation appears. Hosting settings are usually not provided for their editors. - Igor

2 answers 2

Basically, auto-tabulation works if 4 spaces are in a row, if you do not have such large chains of conditions, you can reduce exposures to one space, python supports this. For example, instead of:

x = 5 y = 1 if x > y: y += 1 if y < 0: y = 1 

Write

 x = 5 y = 1 if x > y: y += 1 if y < 0: y = 1 

Even instead of spaces, you can only use tabulation if it already climbs.)

Long lines reduce the readability of the code, in python you can switch to another line before this by putting a \ Example:

 x = 546 y = 234 z = 788 print(x+y+z/y*z*x+len(globals())+6*x \ +z+y+x) 
  • About one space is a great idea! In the vertical orientation on the phone will be more text intermeddle :) And what about the curly braces? Bad bad? def my_func(): {some code} - Skotinin
  • @Skotinin, it's better to have more lines, long lines only spoil the code, in python to transfer the line directly in the expression you can sign \ - Mihail Ris
  • due to this, you can slightly increase the font and not make the lines too short. - Skotinin
  • @Skotinin, I supplemented the answer for a clearer explanation of the use of the \ sign - Mihail Ris
  • @Skotinin, globals () is a standard python function that returns a dictionary of all global names in a program. - Mihail Ris

Python is not interested in how you indent, if you do it equally in the whole module. Python: Myths about Indentation .

Just like in any other language, you do not want to mix tabs with spaces to create indents — this can lead to code that does not work as it seems at first glance. Visual indentation can be misleading, an example for C: Apple's SSL / TLS bug (22 Feb 2014) .

You can use python -tt to automatically check the inconsistent use of tabs. git allows both to convert existing files with tabs, and to prevent the emergence of new such files ( .gitattributes : *.py filter=spabs ). Converting a Git repo from tabs to spaces .

About the "hoster hosted editor": do not use tools that without your knowledge add tabs to the code (no need to drive a nail with a screwdriver) —the same question sounds like you are editing files with your hands on a live server. Instead, the deployment is better to reduce to one team. What this command is: git push or fab deploy or something else - it does not matter: on a home PC, to edit Python code, you can use the editor you need, not the hoster.

On the phone, put an analog Pythonista for iOS .

Editor / IDE with Python support, certainly supports creating / deleting a single key indent (Tab and Backspace respectively). What he writes to the file may depend on the already existing code in the module (if the module uses 2 spaces, Tab will use 2 spaces, if 4, then 4). If you want, you can configure the code to be reformatted when saved in accordance with the selected rules, for example, according to pep-8, using the yapf utility or equivalents .