Single Pound # comments versus Double Pound ## comments

Chad Netzer cnetzer at mail.arc.nasa.gov
Fri Oct 4 20:14:57 EDT 2002


On Friday 04 October 2002 16:45, Terry Hancock wrote:
>
> Seems to me the "###" would currently just get thrown out,
> leaving the dictionary unedited.  Clearly code that relied
> on this would be incompatible with earlier versions of the
> interpreter, but that's a different issue.

I think that is what was meant by it being ambiguous is that it would have 
different (and not always easily separable behavior) on older python.  It is 
a change of behavior for previously valid code.  Just how common it is to 
have ### by itself on a source line, I don't know. :)

> As it stands, if I want this behavior, I can only acheive
> it by editing every line:
> Which is not too bad for a two-line example, but can
> be quite obnoxious for testing larger pieces of code.

As you say, use a smarter editor; or use the "if 0:" idiom to comment out 
blocks of code (again, an auto reindenting editor helps).

And, if  you say that "if 0:" won't work in this case, I say, "true".  You 
could rewrite it as:

this_is_a_dict = {}
this_is_a_dict[ 'spam' ] = 1
this_is_a_dict[ 'ham' ] = 3
this_is_a_dict[ 'eggs' ] = 4
this_is_a_dict[ 'morespam' ] = 2

And then use the "if 0:" idiom.  Or auto-insert of comments.

Ah, but that is all work... Yes.  So, do the benfits outweigh the costs. 
Hmmmm...  Well, I personally am not a big fan of using comments to disable 
code; I guess I've seen WAY to much abuse of it at work and elsewhere.  And 
my editor is more than capable, so perhaps others can weigh in on what it 
would buy them.

-- 

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list