Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to comment lot of lines in python

Reply
Thread Tools

how to comment lot of lines in python

 
 
diffuser78@gmail.com
Guest
Posts: n/a
 
      03-30-2006
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

 
Reply With Quote
 
 
 
 
Felipe Almeida Lessa
Guest
Posts: n/a
 
      03-30-2006
Em Qui, 2006-03-30 Ã*s 15:21 -0800, escreveu:
> Like in C we comment like
> /*
> Bunch of lines of code
> */
>
> Should we use docstring """ """
>
> Or there is something else too ??


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

HTH,

--
Felipe.

 
Reply With Quote
 
 
 
 
Tim Chase
Guest
Posts: n/a
 
      03-30-2006
>>Or there is something else too ??
>
> You should use a decent editor that could automatically
> comment/uncomment code upon your request.


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




 
Reply With Quote
 
Laurent Rahuel
Guest
Posts: n/a
 
      03-31-2006
wrote:

> 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

Hi,

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

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


 
Reply With Quote
 
Eric Deveaud
Guest
Posts: n/a
 
      03-31-2006
wrote:
> Like in C we comment like
> /*
> Bunch of lines of code
> */
>
> Should we use docstring """ """


I would say NO.
docstring are displayed by pydoc, thus a pydoc on your code will display some
inconsistent information

> Or there is something else too ??


some moderns editors allow you to comment/uncomment a selected Bunch
of lines of code

Eric
--
> afin de parfaire mon apprentissage de linux,je cherche sur lille et sa
> périphérie une nana tout linux

JPH in Guide du linuxien pervers : "Connaître le système"
 
Reply With Quote
 
olsongt@verizon.net
Guest
Posts: n/a
 
      03-31-2006

Eric Deveaud wrote:
> wrote:
> > Like in C we comment like
> > /*
> > Bunch of lines of code
> > */
> >
> > Should we use docstring """ """

>
> I would say NO.
> docstring are displayed by pydoc, thus a pydoc on your code will display some
> inconsistent information
>


docstrings are a bit of a magical construct. Not all strings in a
function are docstrings.

>>> def foo():

.... "real docstring"
.... """
.... x=1
.... """
.... print x
....
>>> help(foo)

Help on function foo in module __main__:

foo()
real docstring

>>>


 
Reply With Quote
 
Eric Deveaud
Guest
Posts: n/a
 
      03-31-2006
wrote:
>
> Eric Deveaud wrote:
> > wrote:
> > > Like in C we comment like
> > > /*
> > > Bunch of lines of code
> > > */
> > >
> > > Should we use docstring """ """

> >
> > I would say NO. docstring are displayed by pydoc, thus a pydoc on your
> > code will display some inconsistent information
> >

>
> docstrings are a bit of a magical construct. Not all strings in a
> function are docstrings.



yep fogotten that triple quotted strings are considered as docstring
only if they are the first lines of the module/fonction/class/method
excluding the comments lines.

my bad

Eric

--
SYBEX ORIGINAL SOFTWARE
NOUVEAU KIT LINUX REDHAT 5.2 POUR WIN 95/98
-+- Sybex in Guide du linuxien pervers - "L'incompétance en action" -+-
 
Reply With Quote
 
Michael Hobbs
Guest
Posts: n/a
 
      03-31-2006
Eric Deveaud wrote:
> wrote:
>
>> Eric Deveaud wrote:
>>
>>> wrote:
>>>
>>>> Like in C we comment like
>>>> /*
>>>> Bunch of lines of code
>>>> */
>>>>
>>>> Should we use docstring """ """
>>>>
>>> I would say NO. docstring are displayed by pydoc, thus a pydoc on your
>>> code will display some inconsistent information
>>>
>>>

>> docstrings are a bit of a magical construct. Not all strings in a
>> function are docstrings.
>>

>
>
> yep fogotten that triple quotted strings are considered as docstring
> only if they are the first lines of the module/fonction/class/method
> excluding the comments lines.
>

The official rule is that if *any* string is the first line of a
function/etc, it is considered a docstring. It's just standard
convention to use the triple quotes for docstrings. As you mentioned,
you can use triple quotes for any string; likewise, you can use standard
quotes ( ' or " ) for docstrings as well.

- Mike


 
Reply With Quote
 
Dave Mandelin
Guest
Posts: n/a
 
      03-31-2006
I often use

if 0:
bunch of lines of code

That way, it's very easy to reenable the code, or to add an else, etc.
I can even put things like 'if 0 and USE_FOO_FEATURE' to document what
is being commented out. It's much more flexible than commenting out.

--
Want to play tabletop RPGs over the internet?
Check out Koboldsoft RPZen: http://www.koboldsoft.com

 
Reply With Quote
 
gene tani
Guest
Posts: n/a
 
      03-31-2006

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


scite has a feature where you modify your delimiter in block comments,
i.e. what comes after "#"

http://scintilla.sourceforge.net/SciTEDoc.html

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
First time in one site,lot of free fun,quality DVDmovies,songs,games,drivers and lot of entertainment. nehatoor290@gmail.com C Programming 0 02-22-2009 05:57 PM
ConfigParser: whitespace leading comment lines gwillden@gmail.com Python 1 10-13-2006 05:21 AM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
Find a line, and comment out the next 5 lines joe shaboo Perl 1 04-20-2004 04:24 AM



Advertisments