473,378 Members | 1,522 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

how to comment lot of lines in python

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

Mar 30 '06 #1
19 2185
Em Qui, 2006-03-30 Ã*s 15:21 -0800, di********@gmail.com 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.

Mar 30 '06 #2
>>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


Mar 31 '06 #3
di********@gmail.com 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
"""
Mar 31 '06 #4
di********@gmail.com 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"
Mar 31 '06 #5

Eric Deveaud wrote:
di********@gmail.com 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


Mar 31 '06 #6
ol*****@verizon.net wrote:

Eric Deveaud wrote:
di********@gmail.com 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" -+-
Mar 31 '06 #7
Eric Deveaud wrote:
ol*****@verizon.net wrote:
Eric Deveaud wrote:
di********@gmail.com 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
Mar 31 '06 #8
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

Mar 31 '06 #9

di********@gmail.com 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

Mar 31 '06 #10
Eric Deveaud <ed******@pasteur.fr> wrote:
some moderns editors allow you to comment/uncomment a selected Bunch
of lines of code


Out of curiousity, is there a modern editor which *doesn't* allow you
to comment/uncomment a selected bunch of lines of code?

--
\S -- si***@chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
___ | "Frankly I have no feelings towards penguins one way or the other"
\X/ | -- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
Apr 3 '06 #11
Sion Arrowsmith wrote:
Eric Deveaud <ed******@pasteur.fr> wrote:
some moderns editors allow you to comment/uncomment a selected Bunch
of lines of code


Out of curiousity, is there a modern editor which *doesn't* allow you
to comment/uncomment a selected bunch of lines of code?

TextPad is my editor of choice but it doesn't have this feature.

Kent
Apr 3 '06 #12
Kent Johnson <ke**@kentsjohnson.com> wrote in news:44310867$1_1
@newspeer2.tds.net:
Sion Arrowsmith wrote:
Eric Deveaud <ed******@pasteur.fr> wrote:
some moderns editors allow you to comment/uncomment a selected Bunch
of lines of code


Out of curiousity, is there a modern editor which *doesn't* allow you
to comment/uncomment a selected bunch of lines of code?

TextPad is my editor of choice but it doesn't have this feature.


I use TextPad all the time, and while it is true that the feature is not
built in, it's misleading to say it doesn't have it. It is implemented by
means of a macro definition. I assign a key to a 'comment' macro (basically
replacing regex ^ with '# ' for the selected text) to do this. And of
course I have a reciprocal 'uncomment' macro as well.

--
rzed
Apr 3 '06 #13

Kent Johnson wrote:
Sion Arrowsmith wrote:
Eric Deveaud <ed******@pasteur.fr> wrote:
some moderns editors allow you to comment/uncomment a selected Bunch
of lines of code


Out of curiousity, is there a modern editor which *doesn't* allow you
to comment/uncomment a selected bunch of lines of code?

TextPad is my editor of choice but it doesn't have this feature.

Kent


I also use TextPad - 4.7.3. I have never thought to comment a block of
code, but this thread prompted me to see if it is possible. As far as I
can see, you can do it like this -

Menu > Configure > Block Select Mode - Ctrl+Q,B

Select a block, one column wide, using mouse or keyboard.

Menu > Edit > Fill Block (brings up dialog box)
Fill character: #
Format: Left align
Fill mode: Replace
OK

Done.

To uncomment, as above but set Fill character to a space.

It feels a bit fiddly, but I reckon if you use it a few times it will
become quite smooth.

Frank Millman

Apr 3 '06 #14
Rick Zantow wrote:
Kent Johnson <ke**@kentsjohnson.com> wrote in news:44310867$1_1
@newspeer2.tds.net:
Sion Arrowsmith wrote:
Out of curiousity, is there a modern editor which *doesn't* allow you
to comment/uncomment a selected bunch of lines of code?

TextPad is my editor of choice but it doesn't have this feature.


I use TextPad all the time, and while it is true that the feature is not
built in, it's misleading to say it doesn't have it. It is implemented by
means of a macro definition. I assign a key to a 'comment' macro (basically
replacing regex ^ with '# ' for the selected text) to do this. And of
course I have a reciprocal 'uncomment' macro as well.


Thank you! I don't suppose you have any tricks to make it work with
UTF-8 data outside the cp1252 character set, do you?

Kent
Apr 3 '06 #15
Kent Johnson <ke**@kentsjohnson.com> wrote in
news:44**********@newspeer2.tds.net:
Rick Zantow wrote:
Kent Johnson <ke**@kentsjohnson.com> wrote in news:44310867$1_1
@newspeer2.tds.net:
Sion Arrowsmith wrote:
Out of curiousity, is there a modern editor which *doesn't* allow
you to comment/uncomment a selected bunch of lines of code?

TextPad is my editor of choice but it doesn't have this feature.


I use TextPad all the time, and while it is true that the feature is
not built in, it's misleading to say it doesn't have it. It is
implemented by means of a macro definition. I assign a key to a
'comment' macro (basically replacing regex ^ with '# ' for the
selected text) to do this. And of course I have a reciprocal
'uncomment' macro as well.


Thank you! I don't suppose you have any tricks to make it work with
UTF-8 data outside the cp1252 character set, do you?


Sadly, I don't. TP claims Unicode support, but I'm not sure what they
mean; it does seem to be restricted to cp1252.

--
rzed
Apr 4 '06 #16
Rick Zantow wrote:
Thank you! I don't suppose you have any tricks to make it work with
UTF-8 data outside the cp1252 character set, do you?


Sadly, I don't. TP claims Unicode support, but I'm not sure what they
mean; it does seem to be restricted to cp1252.


TP will correctly read and write UTF-8 files if they use only the
characters available in cp1252. So there is a little Unicode support but
it breaks down pretty quickly with, e.g. Chinese or even Polish.

Kent
Apr 4 '06 #17
> You should use a decent editor that could automatically
comment/uncomment code upon your request.


The Zeus for Windows IDE has just such a feature:

http://www.zeusedit.com/python.html

To do this in Zeus you basically mark the lines of text
that need commenting then use the Macros, Add Comment
Block menu to comment the lines selected.

Then to remove the comments you use the Macros, Remove
Comment Block menu.

Jussi Jumppanen
Author: Zeus for Windows

Apr 4 '06 #18
What's wrong with using three sets of double-quotes? I do it with kwrite
and it works like a charm.

Apr 5 '06 #19
In <00**********************@reece.net.au>, Michael Sperlle wrote:
What's wrong with using three sets of double-quotes?
One can't comment out code that contains multiline strings. Especially
nested comment out does not work.
I do it with kwrite and it works like a charm.


Why not Ctrl+D (comment) and Ctrl+Shift+D (uncomment)?

Ciao,
Marc 'BlackJack' Rintsch
Apr 5 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Riko Wichmann | last post by:
Dear all, is there a way in Python to comment out blocks of code without putting a # in front of each line? Somethings like C's /* block of code here is commented out */ Thanks,
16
by: qwweeeit | last post by:
In analysing a very big application (pysol) made of almost 100 sources, I had the need to remove comments. Removing the comments which take all the line is straightforward... Instead for the...
9
by: Tim Anderson | last post by:
Does anyone else think VB should support the // prefix for comments? I keep using it by accident, because so many other languages use it (unlike the single quote, which is I believe unique to VB)....
16
by: Christopher | last post by:
Hello all, I've got a question of comment logic. I'm trying to determine if a given line of C/C++/C#/Java is a comment or not. Can you please comment on my logic. I need to define some...
3
by: Martin P. Hellwig | last post by:
Hi all, I've been toying with python for about two years now. Not every day, just when I encounter something in my job (sysadmin) repetitively dull. The amazing thing is that like any other...
29
by: dbhbarton | last post by:
Had a thought that's grown on me. No idea if it's original or not- too inexperienced in programming- but I guess there's no harm floating it out there. Python wins big on readability, and...
3
by: Ludwig Miniatur | last post by:
Hi, I ran into a funny thing when I played with the python parser, to build a python call graph for learning... When I have a (special) python program, that runs without any error it gives an...
39
by: polas | last post by:
Afternoon all. I was just wondering about this point - I have (generally) used // for commenting a single line in C, but from looking at code other people have written it seems many use /* */...
3
by: Richard | last post by:
Again, new to DB2. Trying to do something I can do in Sybase ASE. In any Sybase SQL script I can use /* */ to comment out a block of code. In the DB2 9.0 SQL Reference Manual V1 it says: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.