为什么Python会将制表符视为8个空格? [英] Why does Python see a tab as 8 spaces?

查看:142
本文介绍了为什么Python会将制表符视为8个空格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用4个空格的制表符宽度已成为编程的主要选择.那么,为什么Python不将制表符视为4个空格而不是8个空格?

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.

推荐答案

由于Linux控制台中的默认选项卡大小为8个空格,因此Linux中大多数CLI文本编辑器也默认为8个空格.多数也是可配置的,但是它已成为年龄的默认设置.

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.

某些旧(C)代码使用混合缩进以伪造4个空格制表符-1个缩进== 4个空格,2个缩进== 1个制表符,3个缩进== 1个制表符+ 4个空格,等等..不知道是否故意这样做是为了使代码更易于阅读,还是不确定某些编辑器是否自动这样做以模拟4个空格键.我所知道的是,我使用的是pico,它是与之配合使用的PITA,尤其是当您需要缩进/缩进整个块时.:)

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. :)

这篇关于为什么Python会将制表符视为8个空格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆