[Python-ideas] Multi-line comment blocks.

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

David Gates wrote:
> Multi-line strings as comments don't nest, don't play well with docstrings,
> and are counter-intuitive when there's special language support for
> single-line comments. Python should only have one obvious way to do things,

That's not what the Zen says. The zen says:

There should be one-- and preferably only one --obvious way to do it.

which is a positive statement that there should be an obvious way to solve 
problems, NOT a negative statement that there shouldn't be non-obvious ways.

> and Python has two ways to comment, only one of which is obvious. My
> suggestion is to add language support for comment blocks, using Python's
> existing comment delimiter:

There is already support for nested multi-line comments: the humble # symbol 
can be nested arbitrarily deep. All you need is a modern editor that 
understands Python syntax, and with a single command you can comment or 
uncomment a block:

# This is a commented line.

# def fun(a, b, c):
#     """Docstrings are fine when commented"""
#     pass
#     # This is a nested comment.
# And no need for an end-delimiter either.

If your editor is old or too basic, you can do it by hand, which is a pain, 
but doable.

Python doesn't need dedicated syntax to make up for the limitations of your 
editor. Don't complicate the language for the sake of those poor fools stuck 
using Notepad.


More information about the Python-ideas mailing list