Single Pound # comments versus Double Pound ## comments

Terry Hancock hancock at
Sat Oct 5 01:04:00 CEST 2002

From: Tim Peters < at>
> [Manuel M. Garcia]
> > In Python code, does anyone distinguish between
> starting comments with
> > a single pound (#) or a double pound (##)?
> I expect they're just following the convention that #
> means "this is a
> useful comment" and ## means "this section is commented
> out -- pretend it
> doesn't even exist".

I'd like to add that in Zope, when you store Python scripts
on the file system, the meta-data (arguments expected, 
namespace bindings, etc) is stored in a block of double-commented
"##" text at the top of the file. These comments are interpreted
by Zope and are stripped out of the imported file.  I can't
comment on whether this is wise design or not, but that's
how they do it.

It occurs to me, in reference to a previous thread about
blocked-comments, rather than line comments, that having
blocks like:

  This might be a block comment in some hypothetical
  future version of Python. Although I'm not holding
  my breath.

Might be very sensible, analogous to the """ string
definitions.  Since someone pointed out that unused
strings are stripped out, unless they correspond to
docstrings or something, this would have very similar
semantics. Except that it could be more unambiguous --
such as being used to block out code even within

this_is_a_dict = {
Didn't really want this part, but might later:


The nice thing being that you don't have to muddle up
the indentation or edit every single line in the section
you wanted to comment out (or depend on editor gymnastics
to accomplish this for you).

It also seems like this would be moderately easy to
implement, since """ is already caught.  The only
semantic difference would be that ### is always thrown
out (I think this is true anyway).

Despite seeing discussion about block comments on
list, I can't find anything in the PEPs. Am I
looking in the wrong place, or did it just not ever
get that far? Would there be a "sure, send us a patch
cause we don't want to do it" or a "Aaauurrghh! Get
that away from me!" sort of response to this sort
of thing, do you think?

If it's the former, I might have a look at the sources
and see if it's really as simple as I think it must


Terry Hancock
hancock at       
Anansi Spaceworks         
P.O. Box 60583                     
Pasadena, CA 91116-6583

More information about the Python-list mailing list