简体   繁体   English

为什么Python将标签视为8个空格?

[英]Why does Python see a tab as 8 spaces?

Using a tab width of 4 spaces has emerged as the primary choice in programming. 使用4个空格的标签宽度已成为编程的主要选择。 So why doesn't Python see a tab as 4 spaces instead of 8? 那么为什么Python不将标签视为4个空格而不是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. 感觉就像这可以让开发人员免于因不一致的缩进而挣扎。

Because the default tab size in Linux console is 8 spaces, and therefore most CLI text editors in Linux also default to 8 spaces. 由于Linux控制台中的默认选项卡大小为8个空格,因此Linux中的大多数CLI文本编辑器也默认为8个空格。 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. 一些较旧的(C)代码使用混合缩进来伪造4个空格选项卡 - 1个缩进== 4个空格,2个缩进== 1个选项卡,3个缩进== 1个选项卡+4个空格等等......这太糟糕了。 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. 不确定是否有意为了使代码更易于阅读,或者某些编辑自动执行此操作以模拟4个空格选项卡。 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. 我所知道的是,我使用的是pico,而且这是一个与这些人一起工作的PITA,特别是当你需要缩进整个块时。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM