A simple single line, triple-quoted comment is giving syntax error. Why?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Mar 18 18:58:32 EDT 2015


On Thu, 19 Mar 2015 06:53 am, Thomas 'PointedEars' Lahn wrote:

> I must strongly object and recommend against getting accustomed to the
> suggested use of multi-line string literals.

I agree in general with Thomas' comments about using arbitrary strings as
comments. If you want to write code according to *best practices*, then you
should not use strings as comments.

But let's also remember that sometimes you cannot be bothered with *best*
practice, and "good enough for now" practice is fine.

Need to comment out a large block of code in a hurry while using a basic
editor that doesn't offer a "Comment" and "Uncomment" command? Best
practice says I should use a better editor, and that's fine, but right this
instant I'm using the tools I have, not the tools I want, and the easiest
way to fix this is to surround the block of code with triple-quotes. I can
always come back and fix it later. Famous last words, I know, but who among
us can truthfully say they have *never* taken a quick and dirty short-cut
while programming?

I also find it convenient and unobjectionable to include a bare triple
quoted string at the very end of the file, as a sort of "note pad" area for
me to write notes to myself while the work is in early stages of progress.
I can put in small code snippets, URLs to pages I need to look at, general
comments, etc. without having to care about leading # signs. And because I
don't use strings for comments anywhere else, this note pad area stands out
and reminds me to remove it before releasing the code into production.


-- 
Steven




More information about the Python-list mailing list