[Python-ideas] Comment syntax similar to /* */ in C?

Mathias Panzenböck grosser.meister.morti at gmx.net
Sun Oct 18 16:55:31 CEST 2009


I don't think multiline comments are necessary, see:

foobar(a, b, # comment on b
	c, d, e, f)

# comment on b
foobar(a, b, c, d, e, f)

foobar(
	a, # comment on a
	b, # multiline
	   # comment on b
	c, # comment on c
	d, e, f)

However, if multiline comments are introduced they have to be a new syntax
(syntax that produces a syntax error in older python versions) and I also would
like them to by syntactical (nestable), e.g.:

foobar(a, b {* comment on b *}, c, d, e, f)

{*
foobar(a, b {* comment on b *}, c, d, e, f)
egg(spam)
*}
tomato(spam)

On 10/18/2009 03:40 PM, Sturla Molden wrote:
> In Python a comment start from # and spans the rest of the line, similar
> to // in C++.
> 
> In C/C++, we can also make comments that don't span the rest of the
> line, but has two delimiters:
> 
> 
> /* comment */
> 
> 
> This allows us to write:
> 
> 
> foobar(a, b /* comment on b */, c, d, e, f);
> 
> 
> foobar(a, b /* comment on b
>  that spans two lines */, c, d, e, f);
> 
> 
> /* multiline comment
>   often seen in C/C++ code
> 
> */
> 
> 
> 
> 
> I have sometimes missed this possibility when writing Python code. To my
> knowledge there is no equivalent to /* */ in Python.
> 
> I don't care much about choice of delimiter. Perhaps ### comment ### is
> the most intuitive, as it has resemblance to triple-quotes for text
> strings? It also stands out clearly in black/white text.
> 
> 
> foobar(a, b ### comment on b ###, c, d, e, f)
> 
> 
> foobar(a, b ### comment on b
>  that spans two lines ###, c, d, e, f)
> 
> 
> ###
> comment that spans multiple lines
> ###
> 
> 
> If this breaks a lot of existing code, perhaps something else like %%
> could be used?
> 
> 
> foobar(a, b %% comment on b
>  that spans two lines %%, c, d, e, f)
> 
> 
> 
> P.S. In Python we can emulate multiline comments using triple-quoted
> strings, but conceptually strings and comments are very different. I.e.
> strings are objects, comments are auxillary text discarded at compile
> time. Strings are objects created at runtime, comments are not.
> 
> 
> 
> Regards,
> Sturla Molden
> 




More information about the Python-ideas mailing list