469,623 Members | 1,422 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Comments within a line

Has there ever been any discussion of adding comments notation to Python,
such as C++'s /* */, which could occur in the middle of a line or span
multiple lines ? I would like to see it as a more elegant solution for
quickly commenting out code. I am aware of the """ """ technique around
multiple lines but even that seems a poor hack. A comment that could enclose
any sequence of characters would be most welcome.
Jul 18 '05 #1
4 2210
"Edward Diener" <el******@earthlink.net> writes:
Has there ever been any discussion of adding comments notation to Python,
such as C++'s /* */, which could occur in the middle of a line or span
multiple lines ? I would like to see it as a more elegant solution for
quickly commenting out code.


In C/C++, you wouldn't use /* */ for commenting out code, since it
would collide with any comment already there (comments can't be
nested). Instead, the usual way is using #if 0 ... #endif.

You can use "if 0:" with python as well, but of course, you'd have to
indent the entire commented-out block. With most editors, this isn't
much of a problem. I usually use some smaller, "odd" indent than
usual to have an indicication later where the block ends.

- Heike
Jul 18 '05 #2
[Heike C. Zimmerer]
"Edward Diener" <el******@earthlink.net> writes:
Has there ever been any discussion of adding comments notation to
Python, such as C++'s /* */, which could occur in the middle of
a line or span multiple lines ? I would like to see it as a more
elegant solution for quickly commenting out code.

You can use "if 0:" with python as well, but of course, you'd have
to indent the entire commented-out block. With most editors, this
isn't much of a problem. I usually use some smaller, "odd" indent
than usual to have an indicication later where the block ends.


One common trick is to embed a region to comment within triple quotes
(for example, you write ''' (three single quotes) at the beginning of
the text on the first line of your block, and the same after the end of
the text on the last line of your block. I've even read that strings as
statements are optimised out (if not in doc-string position).

I do not use this trick myself. With any reasonable editor, it is very
easy to comment or uncomment a bunch of lines in a simple operation, and
this is neater.

--
François Pinard http://www.iro.umontreal.ca/~pinard
Jul 18 '05 #3
Heike C. Zimmerer wrote:
"Edward Diener" <el******@earthlink.net> writes:
Has there ever been any discussion of adding comments notation to
Python, such as C++'s /* */, which could occur in the middle of a
line or span multiple lines ? I would like to see it as a more
elegant solution for quickly commenting out code.
In C/C++, you wouldn't use /* */ for commenting out code, since it
would collide with any comment already there (comments can't be
nested).


That's true but many times it will not, especially if one comments out code
within a line, or if one is using // liberally also.
Instead, the usual way is using #if 0 ... #endif.
Yes, this is the usual method in C++ which I often use, but Python has no
preprocessor.

You can use "if 0:" with python as well, but of course, you'd have to
indent the entire commented-out block. With most editors, this isn't
much of a problem. I usually use some smaller, "odd" indent than
usual to have an indicication later where the block ends.


Decent idea. Still some sort of multi-line comment notation in Python would
be preferable.
Jul 18 '05 #4
"Edward Diener" <el******@earthlink.net> wrote in message news:<B4******************@newsread2.news.atl.eart hlink.net>...
Heike C. Zimmerer wrote:
"Edward Diener" <el******@earthlink.net> writes:
Has there ever been any discussion of adding comments notation to
Python, such as C++'s /* */, which could occur in the middle of a
line or span multiple lines ? I would like to see it as a more
elegant solution for quickly commenting out code.


In C/C++, you wouldn't use /* */ for commenting out code, since it
would collide with any comment already there (comments can't be
nested).


That's true but many times it will not, especially if one comments out code
within a line, or if one is using // liberally also.


I once saw someone write C code that commented out code with /* */
comments, and then decided he needed to temporarily use that code
again, so he commented out the /* and */ with //'s.
Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

35 posts views Thread by R. Rajesh Jeba Anbiah | last post: by
19 posts views Thread by Alex Vinokur | last post: by
1 post views Thread by George Sakkis | last post: by
3 posts views Thread by Brian | last post: by
3 posts views Thread by psycho | last post: by
reply views Thread by devrayhaan | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.