缩进/空格 [英] Indentation/whitespace

查看:69
本文介绍了缩进/空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Python是否支持s语法不使用它'臭名昭着的

空格规则?我记得读过Python可能包含这样一个

的功能。或者,也许只是一个支撑到缩进预处理器就足够了。


许多人认为Python的语法是有道理的。两种方式都有很强的感觉。它必须依赖于一个人的思维方式,因为我发现它非常令人困惑,即使在使用Python一些

时间后,并试图相信建议我学会喜欢它。

最令人烦恼的是,多个不同的人都很难读。我还是不知道怎么会有人认为重要但是看不见

dedentation是件好事。


注意:无需跟进为什么缩进的长期意见

好​​ - 他们已经被发布了数百次。它似乎只是在某些情况下,Python开发人员认为空白的东西只是

新手的一个问题。我认为很多有经验的用户都不会喜欢它,

而是只是学会忍受它。

Is Python going to support s syntax the does not use it''s infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Many people think Python''s syntax makes sense. There are strong
feelings both ways. It must depend on a person''s way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don''t understand how anybody can think significant-but-invisible
dedentation is a good thing.

Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don''t learn to like it,
but instead just learn to live with it.

推荐答案

Joe写道:
Python是否支持s语法不使用它的臭名昭着的空白规则?我记得读过Python可能包含这样的功能。或者,也许只是一个支撑到缩进预处理器就足够了。

许多人认为Python的语法是有意义的。两种方式都有强烈的感情。它必须依赖于一个人的思维方式,因为我发现它非常令人困惑,即使在使用Python一段时间后,并试图相信我会学会喜欢它的建议最令人讨厌的事情是,多名受访者非常难以理解。我还是不明白为什么有人会认为有意义但又无形的去世是一件好事。

注意:无需跟进长期的意见缩进是好的 - 它们已被发布数百次。看来,Python开发人员认为空白的东西只是新手的问题。我认为很多有经验的用户都不会喜欢它,而是只是学会忍受它。
Is Python going to support s syntax the does not use it''s infamous
whitespace rules? I recall reading that Python might include such a
feature. Or, maybe just a brace-to-indentation preprocessor would be
sufficient.

Many people think Python''s syntax makes sense. There are strong
feelings both ways. It must depend on a person''s way of thinking,
because I find it very confusing, even after using with Python for some
time, and trying to believe the advice that I would learn to like it.
The most annoying thing is that multiple dedents are very unreadable. I
still don''t understand how anybody can think significant-but-invisible
dedentation is a good thing.

Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that
Python developers think the whitespace thing is only an issue for
newbies. I think that many experienced users don''t learn to like it,
but instead just learn to live with it.



将缩进描述为不可见。并不公平。

它比{字符更明显。恕我直言

缩进效果很好。我试图通过PHP跋涉,

JavaScript,使用那些< expletive deleted>

大括号({})的C代码阻塞直到我头疼,特别是如果他们

没有缩进和使用大括号。如果他们缩进

所以我实际上可以阅读代码,为什么还要使用大括号来支持
杂乱无章?我已经解决了多个问题

,插入一个注释,显示缩进块的位置

end(结尾括号(})的位置。

我还发现如果我的缩进超过几个

级别,我可能需要将我的代码重构为更小的

对象或重新考虑这个过程,以便我处理集合

的对象。我已经用多种语言写了

a 32年以上它似乎适用于我。


-Larry


Characterizing indentation as "invisible" isn''t really fair.
It it WAY more visible than a { character. IMHO the
indentation works very well. I''ve tried to wade through PHP,
JavaScript, C code that uses those <expletive deleted>
brace ({}) blocks until my head hurt, especially if they
didn''t indent as well as using the braces. If they indent
so I can actually read the code, why also use braces to
clutter things up? I''ve solved the multiple dedent problem
by inserting a comment that shows where the indented blocks
end (sort of where the ending brace (}) would have been.
I also find that if I''m indenting more than a couple of
levels, I probably need to refactor my code into smaller
objects or rethink the process so that I process collections
of objects. I''ve written in many different languages over
a span of 32+ years and it seems to work for me.

-Larry


Joe< jk **** @ nc.rr.com>写道:
Joe <jk****@nc.rr.com> wrote:
Python是否支持s语法不使用它的臭名昭着的空白规则?


不,从不(偶数)除了它与它之间的问题...... ;-)。

我记得读过Python可能包含这样的功能。


我记得读过Elvis是st生病了,被外国人绑架了,但是我并不一定相信我读过的所有东西。

或者,也许只是一个支撑到压痕的预处理器会是
足够了。


很好,然后写一个 - 这不是太难(关于平均面试

招聘程序员的问题,我会说)。至于如何将这样的预处理器与CPython集成在一起,我建议你通过允许任意的源代码读取钩子来跟随先例

。可选择通过设置sys.preprocessor(和/或通过命令行标志,

环境变量等)指定
- 但是,能够从
site-configure.py可能就足够了。


你可以通过使用现有的import
获得99%的收益
hooks"机制(允许你从zipfiles导入的同一个:它是

设计为易于扩展),但我认为这不会有帮助

with 主要脚本 (没有进口),互动

口译员会议等;另外,我不确定它是否会轻易地允许

与其他此类钩子无缝互操作(例如,让你从需要预处理的zipfiles源导入

) 。


我建议预处理器连接的通用机制的主要原因是这样的机制可能有机会成为

接受(通过通常的PEP程序),只要其他有趣的用途可以找到
的情况;我怀疑,如果唯一的用例是将支撑物转换为缩进/延迟,那么PEP就没有机会了。


例如,小而有声的少数群体长期以来一直竞选

非ASCII字符在标识符中被允许;预处理器可能会通过将它们动态转换为ASCII来实现这一点(尽管

对于getattr和朋友来说并不一定能很好用......但是

然后,私人标识符也不以两个下划线开头;-)。

仍然不明白任何人如何能够认为重要但不可见< dedentation是一件好事。


我们甚至,因为我无法理解反向;-)。

注意:无需跟进为什么缩进是好的意见 - 他们已被发布数百次。它似乎只是
Is Python going to support s syntax the does not use it''s infamous
whitespace rules?
No, never (even apart from the "its" vs "it''s" issue here...;-).
I recall reading that Python might include such a
feature.
And I recall reading that Elvis is still alive and was kidnapped by
aliens, but I don''t necessarily believe all that I read.
Or, maybe just a brace-to-indentation preprocessor would be
sufficient.
Fine, then write one -- it''s not too hard (about an average interview
question for hiring a programmer, I''d say). As for how to integrate
such a preprocessor with CPython, I would suggest you follow precedent
by allowing an arbitrary "source-code-reading hook" to be optionally
specified by setting sys.preprocessor (and/or via commandline flag,
environment variable, etc -- but, the ability to install the hook from
site-configure.py would probably be sufficient).

You could maybe get 99% of the way there by using the existing "import
hooks" mechanism (the same one that lets you import from zipfiles: it''s
designed to be easily extensible), but I don''t think that would help
with the "main script" (which doesn''t get imported), interactive
interpreter sessions, etc; also, I''m not sure it would easily allow
seamless interoperation with other such hooks (e.g., to let you import
from zipfiles sources that need to be preprocessed).

The main reason I suggest a general-purpose mechanism for the hooking-up
of the preprocessor is that such a mechanism might stand a chance to be
accepted (via the usual PEP procedure), as long as other interesting use
cases can be found; I suspect that if the only use case was "turn braces
into indents/dedents", the PEP would stand no chance.

For example, a small but vocal minority has long campaigned for
non-ASCII characters to be allowed in identifiers; a preprocessor might
be able to do this by translating them into ASCII on the fly (though
that wouldn''t necessarily work well with getattr and friends... but
then, neither do ''private'' identifiers starting with two underscores;-).
still don''t understand how anybody can think significant-but-invisible
dedentation is a good thing.
We''re even, then, since I can''t understand the reverse;-).
Note: No need to follow up with long opinions of why indentation is
good -- they have been posted hundreds of times. It just seems that




尊重你的愿望,我根本不讨论这个问题(尽管,通过

试图制作一些反对它,你真的很难:如果

你不想要这样的讨论你不应该自己开始一个和

然后试图阻止你的对手反驳你的观点,那就是你真的是一个非常不公平的尝试。如果你愿意为

目的做一些工作,我指着你

你可能会得到你的愿望。对预处理器进行编码是很容易的部分 - 在进行PEP时,工作主要是

,包括用于一般

目的预处理器的各种强大用例。 (当然,要求Python硬编码你的

预处理器更容易,但分叉总是有其他问题)。

Alex



Respecting your wish, I''m not discussing the issue at all (although, by
trying to make some point AGAINST it, you really make it very hard: if
you don''t want such a discussion you shouldn''t start one yourself and
then try to impede your opponents from rebutting your points, that is
really an extremely unfair attempt on your part). I''m pointing you to
ways you might get your wish, if you''re willing to do some work for the
purpose. Coding the preprocessor is the easy part -- the work is mostly
in doing the PEP, including a variety of strong use cases for a general
purpose preprocessor. (Of course, forking Python to hardcode your
preprocessor is easier, but forking always has other problems).
Alex


Alex Martelli写道:
Alex Martelli wrote:
我建议用于预处理器连接的通用机制的主要原因是这样的机制可能有机会接受(通过通常的PEP程序),只要其他有趣的用途可以找到;我怀疑,如果唯一的用例是将支架转换为缩进/延迟,那么PEP就没有机会。
The main reason I suggest a general-purpose mechanism for the hooking-up
of the preprocessor is that such a mechanism might stand a chance to be
accepted (via the usual PEP procedure), as long as other interesting use
cases can be found; I suspect that if the only use case was "turn braces
into indents/dedents", the PEP would stand no chance.




+ 1预处理器的想法,特别是如果它允许我们在AST级别挂钩

。 (没有对curlies的评论。;)


Dave



+1 on the preprocessor idea, especially if it would allow us to hook in
at the AST level as well. (No comment on the curlies. ;)

Dave


这篇关于缩进/空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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