473,480 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 2329
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4644
by: lorinh | last post by:
Hi Folks, I'm trying to strip C/C++ style comments (/* ... */ or // ) from source code using Python regexps. If I don't have to worry about comments embedded in strings, it seems pretty...
35
2938
by: R. Rajesh Jeba Anbiah | last post by:
Nowadays in PHP world, the "noise" is about upcoming PHP6 <http://phplens.com/phpeverywhere/?q=node/view/212> <http://www.planet-php.net/>. Do c.l.php readers have any comments or suggestions? ...
19
5662
by: Alex Vinokur | last post by:
Is there any tool to count C-program lines except comments? Thanks, ===================================== Alex Vinokur mailto:alexvn@connect.to http://mathforum.org/library/view/10978.html...
10
2067
by: Monk | last post by:
Hi, Have a query regarding comments that extend over multiple-lines. Would like to know if the standard's view of this, so that we can create a code which doesn't run into compiler specific...
98
4482
by: tjb | last post by:
I often see code like this: /// <summary> /// Removes a node. /// </summary> /// <param name="node">The node to remove.</param> public void RemoveNode(Node node) { <...> }
1
1230
by: George Sakkis | last post by:
The tokenize.generate_tokens function seems to handle in a context- sensitive manner the new line after a comment: .... # hello world .... x = ( .... # hello world .... ) .... ''' .... ...
3
1323
by: Brian | last post by:
Hi, I am trying to format my comments for my class library. how do i insert new line feed so that all the text is not just jumbled in together Brian
3
4329
by: psycho | last post by:
I had created a class and added XML comments to its methods. Then I compiled it as a DLL and added its reference to my project. But when I type the names of its methods, the intellisense is not...
0
7051
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6915
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7097
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6750
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6993
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
2993
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
567
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.