问题
Using a tab width of 4 spaces has emerged as the primary choice in programming. So why doesn't Python see a tab as 4 spaces instead of 8?
Is there a (technical, historic, other) reason for this design decision? It feels like that could have saved developers from struggling with inconsistent indentation a lot.
回答1:
Because the default tab size in Linux console is 8 spaces, and therefore most CLI text editors in Linux also default to 8 spaces. Most are also configurable, but it's been the default for ages.
Some older (C) code uses mixed indention to fake a 4 space tab - 1 indent == 4 spaces, 2 indents == 1 tab, 3 indents == 1 tab + 4 spaces, etc..... it was awful. Not sure if it was done intentionally in order to make the code easier to read, or if some editor did this automatically to simulate 4 space tabs. All I know is that I was using pico and it was a PITA working with those, especially when you needed to indent/dedent a whole block. :)
来源:https://stackoverflow.com/questions/23415525/why-does-python-see-a-tab-as-8-spaces