Hm, what about sys.exit(0)
? (assuming you do import sys
above it, of course)
As to why it would useful, sometimes I sit down to do a substantial rewrite of something and want to mark my "good up to this point" place.
By using sys.exit(0)
in a temporary manner, I know nothing below that point will get executed, therefore if there's a problem (e.g., server error) I know it had to be above that point.
I like it slightly better than commenting out the rest of the file, just because there are more chances to make a mistake and uncomment something (stray key press at beginning of line), and also because it seems better to insert 1 line (which will later be removed), than to modify X-many lines which will then have to be un-modified later.
But yeah, this is splitting hairs; commenting works great too... assuming your editor supports easily commenting out a region, of course; if not, sys.exit(0)
all the way!
__END__
is useful for many things, I've used it for long form documentation at the end, or as a place to throw a copy of a block of code if doing a major refactor, and I use it all the time on my "scratchpad" file where I do small code tests. finish a test, slap__END__
on top, and onto the next test. That way the file keeps a running history of what I've worked on. – Eric Strom Mar 18 '10 at 20:29__END__
in tests sometimes. The use case is braindumping code, and then gradually getting it to compile and pass. As the top starts to compile, you move__END__
down a test case or two, and then work on those... and then repeat the process. If you are usinggit snapshot-watch
, it's all "version controlled" anyway.__END__
just saves you some typing and munging. – jrockway Mar 19 '10 at 3:46__END__
used where someone wanted to include data in the executable itself. I.e: the file is an python script and yaml file. I know this is considered bad practice. However, "why the #&%! would you want to do that?" isn't an answer. – Austin Richardson Jun 29 '10 at 17:20