comment out more than 1 line at once?

Peter Hansen peter at
Tue Nov 30 16:14:24 CET 2004

Gustavo Córdova Avila wrote:
> Riko Wichmann wrote:
>> is there a way in Python to comment out blocks of code without putting 
>> a # in front of each line? Somethings like C's
> I haven't seen the "other" way to block-comment multiple
> lines of code: triple-quoted strings.

Building on this thought: it's very effective to write all
your "real" triple-quoted strings (usually they're the doc-comments,
but not always) using one type of quotation mark, thus reserving
the other type for use as temporary "commenting" as Riko asks:

def func(foo, bar):
     '''this function spams a foo with a bar'''

If you're consistent about it, it's at least as effective as
multi-line comment in other languages for this purpose.

> Strings which are unassigned in a source file are dropped
> by the compiler, so they don't make it to the execution
> stage; they're nice that way.

Not that it matters, but note that the first "unassigned"
string in a file (or class, or function, etc) will not be
dropped but will be available as the __doc__ attribute of
the module, class, function, or whatever.

I guess this could matter if someone was trying to ship
only .pyc files, thought that some critical and/or embarrassing
code was actually eliminated, but found out that it was
all nicely visible in the doc-comment for the module in


More information about the Python-list mailing list