Why does Python see a tab as 8 spaces?

好久不见. 提交于 2019-12-14 01:05:04

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!