[Python-ideas] Multi-line comment blocks.

Steven D'Aprano steve at pearwood.info
Sat Jun 16 08:55:51 CEST 2012

Carl Meyer wrote:

> The reason I discourage using multi-line strings as comments is that
> they don't nest (which I think David mentioned earlier). If you've got a
> short multi-line-string-as-comment in the middle of a function, and then
> you try to use multi-line-string technique to comment out that entire
> function, you don't get what you want, you get a syntax error as your
> short comment is now parsed as code.

You can nest two such string-comments, by using different string delimiters:

'''Outermost comment

def func(x, y):
     """Innermost comment or docstring
     goes here


If you regularly need to do this, you're doing it wrong.
You should be deleting unused code, not commenting it
out. Nested comments as change tracking is *worse* than
no change tracking, in my opinion.

> (FWIW, I don't think this means Python needs a dedicated syntax for
> multi-line comments, I think multiple lines beginning with # works just
> fine.)



More information about the Python-ideas mailing list