为什么在Python中没有块注释? [英] why no block comments in Python?

查看:198
本文介绍了为什么在Python中没有块注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还在想弄清楚什么是Pythonic。意思是,我有一个

感觉我的问题的答案可能属于那个类别。是块

以某种方式评论unpythonic吗?

I''m still tyring to figure out what "Pythonic" means, and I have a
feeling the answer to my question may fall into that category. Are block
comments somehow unpythonic?

推荐答案

John Salerno写道:
John Salerno wrote:
我还在想弄清楚什么是Pythonic。意思是,我有一种感觉,我的问题的答案可能属于这一类。阻止
评论某种方式是unpythonic吗?
I''m still tyring to figure out what "Pythonic" means, and I have a
feeling the answer to my question may fall into that category. Are block
comments somehow unpythonic?




只是因为python没有它们。


但如果你有一位现代编辑,他们就毫无意义了。


(如果你不这样做,你可以通过放置区域来快速评论区域

在一个三重引号的字符串中。)


< / F>



only in the sense that python don''t have them.

but they''re pretty pointless, if you have a modern editor.

(and if you don''t, you can quickly comment out regions by putting them
inside a triple-quoted string.)

</F>


Fredrik Lundh < FR ***** @ pythonware.com>写道:
Fredrik Lundh <fr*****@pythonware.com> wrote:
你可以通过将它们放在一个三重引号的字符串中快速注释掉区域。)
you can quickly comment out regions by putting them
inside a triple-quoted string.)




除了三重-quotes不要窝。


我同意,但是,任何体面的编辑应该是

能够注释掉一块代码比我输入的代码更快

句子。



Except that triple-quotes don''t nest.

I do agree, however, with the idea that any decent editor should be
able to comment out a block of code faster than I can type this
sentence.


很明显,如果你有一个现代编辑器,块注释是

是不必要的,因为在每行的开头添加#是微不足道的
块的
,但这并没有真正回答你的问题。它解释了

为什么你可能并不总是需要块注释但是没有解释为什么你不应该使用它们(特别是在原始编辑器中)。


阻止评论的危险在于,没有办法告诉您正在查看的

代码已被注释掉,除非您看到

注释块的开头或结尾。如果你有一个现代编辑器,它可能会改变所有注释掉的代码的颜色以消除

的混乱。但如果你有一个原始的编辑器,它不会。此外,即使是使用现代编辑的人也会使用

纯文本查看器(更少/更多)来浏览源代码。


消除块注释消除了不确定性。 :)

It''s clear that if you have a modern editor, block comments are
unnecessary because it is trivial to add a # to the start of each line
of a block, but that doesn''t really answer your question. It explains
why you might not always need block comments but doesn''t explain why
you shouldn''t use them (especially in a primitive editor).

The danger with block comments is that there is no way to tell that the
code you''re looking at has been commented out unless you can see the
start or end of the comment block. If you have a modern editor, it
probably changes the color of all commented out code to eliminate
confusion. But if you have a primitive editor it does not. Also, even
people who use modern editors sometimes browse source code using a
plain text viewer (less/more).

Eliminating block comments eliminates uncertainty. :)


这篇关于为什么在Python中没有块注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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