如何在python中评论很多行 [英] how to comment lot of lines in python

查看:83
本文介绍了如何在python中评论很多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C中我们评论如

/ *

一串代码

* /


我们应该使用docstring""" """


或者还有其他的东西?


我们非常感谢您的帮助。

谢谢

Like in C we comment like
/*
Bunch of lines of code
*/

Should we use docstring """ """

Or there is something else too ??

Every help is appreciated.

Thanks

推荐答案

Em Qui,2006-03-30?* s 15:21 -0800, di ******** @ gmail.com escreveu:
Em Qui, 2006-03-30 ?*s 15:21 -0800, di********@gmail.com escreveu:
喜欢C我们评论如
/ *
一串代码
* /

我们应该使用docstring""" 或还有其他东西?
Like in C we comment like
/*
Bunch of lines of code
*/

Should we use docstring """ """

Or there is something else too ??




你应该使用一个可以自动
根据您的要求评论/取消注释代码。


HTH,


-

Felipe 。



You should use a decent editor that could automatically
comment/uncomment code upon your request.

HTH,

--
Felipe.


>>或者还有别的东西?
>>Or there is something else too ??

你应该使用一个不错的编辑器可以根据您的要求自动评论/取消注释代码。

You should use a decent editor that could automatically
comment/uncomment code upon your request.




在Vim中,您可以映射一个键来执行以下操作:


:s / ^ /#


来评论突出显示的行,并且


:s / ^#


取消注释它们。要映射它们,您可以使用


:vnoremap< f4> :s / ^ /#< cr>

:vnoremap< f5> :s /#< cr>


(这些是文字的小于,[" eff,[4 | 5]" |"见,
是],大于字符


然后,按< f4>在视觉模式下,将评论所选的

行,然后按< f5>将取消评论任何选定的行

评论。


关于vim执行此操作的方法的好处是,你是

可以将它与grepping结合起来。如果你想评论

每行包含一个正则表达式,你可以做


:g / regexp / s / ^ /#


或者,如果你想从regexp_1中注释掉到包含regexp_2的行后面的

,你可以使用


:g / regexp_1 /.,/ regexp2 / s / ^ /#


各种方便的技巧。


有些python插件我肯定能提供这样的能力

建成-在。有可能在其他编辑器中执行此操作

。我恰好是一个vim sorta家伙。


-tkc




In Vim, you can map a key to do the following:

:s/^/#

to comment the highlighted lines, and

:s/^#

to uncomment them. To map them, you can use

:vnoremap <f4> :s/^/#<cr>
:vnoremap <f5> :s/#<cr>

(those are literal "less-than, ["eff, [4 | 5]" | "see,
are"], greater-than" characters)

Then, pressing <f4> in visual mode will comment the selected
lines, and pressing <f5> will uncomment any selected lines
that are commented.

The nice thing about vim''s method of doing this, is that you
can combine it with grepping. If you want to comment out
every line containing a regexp, you can do

:g/regexp/s/^/#

Or, if you want to comment out from "regexp_1" to the
following line containing "regexp_2", you can use

:g/regexp_1/.,/regexp2/s/^/#

All sorts of handy tricks.

There are python plugins that I''m sure offer such abilities
built-in. There are likely ways to do this in other editors
too. I just happen to be a vim sorta guy.

-tkc



di ******** @ gmail.com 写道:
di********@gmail.com wrote:
就像在C中我们一样评论
/ *
一堆代码串
* /

我们应该使用docstring""" 或还有其他的东西?

感谢每一个帮助。

谢谢
Like in C we comment like
/*
Bunch of lines of code
*/

Should we use docstring """ """

Or there is something else too ??

Every help is appreciated.

Thanks






也许这听起来比regexp简单,所以,只需使用""标记如

这个:


"""

这个

将是

评论

期间

执行

"""


Hi,

Maybe this sounds simplier than regexp and so, just use the """ marker like
this :

"""
this
would be
commented
during
execution
"""


这篇关于如何在python中评论很多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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