问题描述
我是唯一一个认为python语句应该在它们之前和之后强制使用
空格的人吗?
现在这不是强制执行的例如这些陈述是
有效
print" hello"
" foo" if" bar" else" foobar" :print(x,y)
[(y)for(x, y)in [(foo,2),(bar,4)]如果(x)中的foo]
....等等。
我知道编写这样的代码真的不应该这样做但是
强制使用是不是一个好主意
语句周围的空白?
(我在这里写了一篇关于此的短篇博文
但我想我会在这里发布看看其他什么开发商
想想)
- Bj?rnKempén
Am I the only one that thinks that python statements should force
whitespace before and after them?
Right now this is not enforced and for an example these statements are
valid
print"hello"
"foo"if"bar"else"foobar"
for(x,y)in[(1,2),(3,4)]:print(x,y)
[(y)for(x,y)in[("foo",2),("bar",4)]if"foo"in(x)]
....and so on.
I know that writing code like this really shouldn''t be done but
wouldn''t it be a good idea to enforce the use of whitespace around
statements?
(I wrote a short blog post about this here http://blog.buffis.com/?p=55
but thought I would post here as well to see what other developers
think)
- Bj?rn Kempén
推荐答案
你可能有一点 - 但另一方面,这可能是有目的的
允许帮助招募perl程序员。
James
You may have a point--but on the other hand, this may be purposefully
allowed help to recruit perl programmers.
James
另一方面,这也差一点:
[(y)for [x,y] in [(" foo" ,2),(bar,4)]如果foo, in(
x)]
而且我不想记住所有关于什么可以和/ b
的规则以及什么可以不,特别是在调试的时候。没有。
我认为不应该强迫它,但可能会把它放在PEP8或PEP3008中。
另外,我唯一能找到的东西在所有这些中令人不愉快的问题是b $ b乱七八糟。字符。其余的至少是b
一目了然哪些属于哪里。
另外,你需要以下吗?
my_function(swallow ='''欧洲'')
因为这只是对空白的可怕使用。
干杯,
Cliff
On the other hand, this is just as bad:
[ ( y ) for ( x , y ) in [ ( "foo" , 2 ) , ( "bar" , 4 ) ] if "foo" in (
x ) ]
And I''d hate to have to remember all of the rules for what can go
together and what can''t, especially when it comes time to debug. No.
I don''t think it should be forced, but maybe put it in PEP8 or PEP3008.
Also, the only thing I find thoroughly disagreeable in all of that
mess, is the run-ins involving " characters. The rest are at least
clear at a glance what belongs where.
Also, would you require the following?
my_function (swallow=''European'')
Because that is just an awful use of whitespace.
Cheers,
Cliff
它是:参见表达式和语句中的空格在PEP 8中。
-
书签:
这篇关于不强制空格的Python语句很混乱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!