![bbedit auto indent bbedit auto indent](https://i.stack.imgur.com/lQeUX.png)
However this does not apply to Python 3 anymore - in Python 3 mixing of spaces and tabs are always an error - tabs only match tabs and spaces only match other spaces in indentation that is a block indented with TAB SPACE SPACE might contain a block indented with TAB SPACE SPACE TAB, but not one indented with TAB TAB TAB, it would be considered an indentation error, even though the block would seemingly extend further:
![bbedit auto indent bbedit auto indent](https://powerspreadsheets.com/wp-content/uploads/auto-indent-code.jpg)
In Python 2, the interpretation of TAB is as if it is converted to spaces using 8-space tab stops (as provided by previous answers already) that is that each TAB furthers the indentation by 1 to 8 spaces so that the resulting indentation is divisible by 8. (Google's coding standards say 'use 2 spaces'.) PEP8 says 'use 4 spaces per indentation level'. It is best - necessary in Python 3 - to ensure that the sequence of characters making up the indentation on each line in a block is identical. This means that the TAB vs 8-space example that worked in Python 2 would generate a TabError in Python 3. Indentation is rejected as inconsistent if a source file mixes tabs and spaces in a way that makes the meaning dependent on the worth of a tab in spaces a TabError is raised in that case. (Apart from the opening word "First," these are identical.)
![bbedit auto indent bbedit auto indent](https://1stwebdesigner.com/wp-content/uploads/2010/03/coding-editors-windows/coda-coding-editors-for-windows.jpg)
Indentation cannot be split over multiple physical lines using backslashes the whitespace up to the first backslash determines the indentation. The total number of spaces preceding the first non-blank character then determines the line’s indentation. Tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight (this is intended to be the same rule as used by Unix). Compare:įirst, tabs are replaced (from left to right) by one to eight spaces such that the total number of characters up to and including the replacement is a multiple of eight (this is intended to be the same rule as used by Unix). In Python 3, the rules are slightly different (as noted by Antti Haapala).
#Bbedit auto indent code#
In Python 2, this code works, printing nothing. As Alex Martelli points out in a comment, in Python 2, tabs are equivalent to 8 spaces, and adapting the example with a tab and 8 spaces shows that this is indeed the case. Oops - embarrassing my proof by counter-example shows that tabs are not equivalent to 4 spaces. Thus showing that in Python 2.5, tabs are not equal to spaces (and in particular not equal to 4 spaces). IndentationError: unindent does not match any outer indentation level When run through Python 2.5, I get the error: File "xx.py", line 4 Proof by counter-example ( erroneous, or, at best, limited - tab != 4 spaces): x = 1 A line indented with a tab is at a different indentation from a line indented with 1, 2, 4 or 8 spaces. Spaces are not treated as equivalent to tab.