Comments within a line

François Pinard pinard at iro.umontreal.ca
Sat Jul 31 08:39:50 EDT 2004


[Heike C. Zimmerer]
> "Edward Diener" <eldiener at 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



More information about the Python-list mailing list