What's the word on using """ to comment-out?

Tim Chase python.list at tim.thechases.com
Thu Feb 25 05:44:31 EST 2010


Paul Rudin wrote:
> kj <no.email at please.post> writes:
> 
>> I think I remember, early in my learning of Python, coming across
>> the commandment "THOU SHALT NOT USE TRIPLE-QUOTES TO COMMENT-OUT
>> LINES OF CODE", or something to that effect.  But now I can't find
>> it!
> 
> No idea, but it would be nice to have some multiline comment syntax
> (other than # at the beginning of each line). Particularly one that can
> be nested.

Well, there's always "if 0"/"if False", but that requires 
screwing with the indentation levels.  Granted, any competent 
text editor will allow you to easily shift code indentation (I 
know Vim does, and am pretty sure Emacs will let you do the 
same...YMMV with other editors).

But yes, there have been times that a multi-line commenting that 
doesn't touch your indentation would be nice, and I confess to 
using triple-quotes to do that (opting for """ or ''' based on 
the type of triple-quotes found in the code).  However, I usually 
limit this for debugging purposes and they usually get pruned or 
uncommented for production code.

-tkc






More information about the Python-list mailing list