Single Pound # comments versus Double Pound ## comments

Tim Peters at
Fri Oct 4 16:14:40 EDT 2002

[Manuel M. Garcia]
> In Python code, does anyone distinguish between starting comments with
> a single pound (#) or a double pound (##)?

I introduced two conventions of this nature in the early days of the Emacs
Python mode:  ## was used by the comment-region command to "comment out" a
contiguous block of code.  Many others have done likewise.  In addition,
Python mode makes a distinction between "indenting comment lines" and
"non-indenting comment lines".  If a line starting with # has whitespace
immediately following, and you hit ENTER/RETURN, Python mode reproduces its
indentation on the new line; if it doesn't have whitespace immediately
following (like '##' or '#...'), then its indentation is ignored, and Python
mode looks backwards for the closest-preceding statement to mimic.

> ActivePython colorizes them differently (# - green, ## - gray), and
> not understanding the distinction implied is bugging me.

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".

More information about the Python-list mailing list