为什么Python样式指南(PEP-8)说4个空格缩进而不是8个空格? 8空间缩进永远可以吗? [英] Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok??
问题描述
Linux内核风格指南,Guido的C风格指南和(我相信)旧的
K& R风格推荐8个空格缩进。
我终于确信了8个空格缩进的智慧。
Guido也喜欢8个空格缩进FOR C CODE。
为什么样式指南( PEP-8)for Python说4个空格缩进???
打破规则,到处使用8个空格缩进
a真的不好主意??
我真的很想做我的开源PYTHON项目
有8个空间ID !!!!
Chris
Linux kernel style guide, Guido''s C style guide and (I believe) old
K&R style recommends 8 SPACES for indent.
I finally got convinced of wisdom of 8 space indentation.
Guido also likes 8 space indentation FOR C CODE.
Why style guide (PEP-8) for Python says 4 space indents???
Is breaking rule to use 8 space indents everywhere
a REALLY bad idea??
I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!
Chris
推荐答案
Christian Seberino写道:
Christian Seberino wrote:
Linux内核风格指南,Guido'的C风格指南和(我相信)旧< K& R风格推荐8个空格用于缩进。
我终于确信了8个空格缩进的智慧。
Guido也喜欢8个空格缩进FOR C CODE。
为什么样式指南(PEP-8)适用于Python sa是4个空格缩进???
打破规则,到处使用8个空格缩进
一个真正的坏主意?
我真的想要做我的开源PYTHON项目
有8个空间ID !!!!
Chris
Linux kernel style guide, Guido''s C style guide and (I believe) old
K&R style recommends 8 SPACES for indent.
I finally got convinced of wisdom of 8 space indentation.
Guido also likes 8 space indentation FOR C CODE.
Why style guide (PEP-8) for Python says 4 space indents???
Is breaking rule to use 8 space indents everywhere
a REALLY bad idea??
I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!
Chris
我没有正式答案,但是这是我的猜测:
a)
在C中,新行通常与任何其他空格一样(
$除外) b $ b strings,C ++ // comments),这样你就可以轻松地将新行放在表达式的中间位置。
在Python中,换行符是重要的,除了列表,元组等。
和其他一些案例,所以你通常必须在语句中使用\
来逃避它们。如果你在Python中使用8空格缩进,你很快就会不得不逃避很多新行,这很烦人。
b)
除非你有一个编辑器将标签转换为固定数量的
空格,否则键入8个空格是一件痛苦的事。即使是将标签转换为空格的编辑也可能无法通过相同数量的
空格提供简单的缩进方式
--------
当然,这两个原因都意味着2个空格优于
4.使用4个空格可能选择作为点之间的折衷a)
和b)并确保压痕水平清晰可见。
David
I don''t have an official answer, but here are my guesses:
a)
In C, new lines are generally like any other white space (except within
strings, C++ // comments), so you can easily put new lines in the middle
of an expression.
In Python, newlines are significant, except within lists, tuples, etc.
and a few other cases, so you generally have to escape them with \
within statements. If you use 8-space indents in Python, you very
quickly end up having to escape a lot of new lines, which is annoying.
b)
Unless you have an editor which converts tabs to a fixed number of
spaces, typing 8 spaces is a pain. Even editors which do convert tabs
to spaces may not provide an easy way to un-indent by the same number of
spaces
--------
Of course, both these reasons would imply that 2 spaces was better than
4. Using 4 spaces was probably chosen as a compromise between points a)
and b) and making sure that the indentation level was clearly visible.
David
Christian Seberino写道:
Christian Seberino wrote:
我真的想做我的开源PYTHON项目
有8个空间ID! !
I REALLY WANT TO DO MY OPEN SOURCE PYTHON PROJECT
WITH 8 SPACE IDENTS!!!!
你真的不认为风格指南会阻止你这么做吗?你知道吗?
-
Erik Max Francis&& ma*@alcyone.com && http://www.alcyone.com/max/
__美国加利福尼亚州圣何塞市&& 37 20 N 121 53 W&& & tSftDotIotE
/ \高尔夫是一个很好的散步。
\ __ /马克吐温
You don''t really think a style guide is going to stop you from doing
that, do you?
--
Erik Max Francis && ma*@alcyone.com && http://www.alcyone.com/max/
__ San Jose, CA, USA && 37 20 N 121 53 W && &tSftDotIotE
/ \ Golf is a good walk spoiled.
\__/ Mark Twain
" David C. Fox" <哒******* @ post.harvard.edu>在消息中写道
news:FYDlb.2596
"David C. Fox" <da*******@post.harvard.edu> wrote in message
news:FYDlb.2596
这篇关于为什么Python样式指南(PEP-8)说4个空格缩进而不是8个空格? 8空间缩进永远可以吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!