exit a program gracefully

Cameron Simpson cs at zip.com.au
Tue May 5 07:42:00 EDT 2009


On 05May2009 23:28, Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> wrote:
| In message <mailman.5079.1241476454.11746.python-list at python.org>, Gabriel 
| Genellina wrote:
| 
| > I prefer to put the code inside a function, and just `return` earlier.
| 
| It would be nice if Python offered a straightforward equivalent to
| 
|     ... initialization goes here ...
|     do /*once*/
|       {
|         ... do stuff ...
|         if (check1_failed)
|             break;
|         ... do more stuff ...
|         if (check2_failed)
|             break;
|         ... do even more stuff ...
|       }
|     while (false);
|     ... cleanup goes here ...

  while True:
    ... do stuff ...
    if check1_failed:
      break;
    ... do more stuff ...
    if check2_failed:
      break;
    ... do even more stuff ...
    break
  ... cleanup goes here ...

Seems more straightforward to me!

And there's always try/except and context managers.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

So why can't we celebrate November 5th the way Guy Fawkes would've wanted?
        - Mike Holmes <fofp at tattoo.ed.ac.uk>



More information about the Python-list mailing list