Pythonic way to determine if a string is a number

Christian Heimes lists at cheimes.de
Sun Feb 15 15:04:49 EST 2009


Roy Smith wrote:
> I agree that the bare except is incorrect in this situation, but I don't 
> agree that you should *never* use them.

A bare except should be used when followed by a raise

try:
   func()
except:
   log_error()
   raise

> They make sense when you need to recover from any error that may occur, 
> possibly as the last resort after catching and dealing with more specific 
> exceptions. In an unattended embedded system (think Mars Rover), the 
> top-level code might well be:
> 
> while 1:
>    try:
>       main()
>    except:
>       reset()

Do you really want to except SystemExit, KeyboardInterrupt, MemoryError
and SyntaxError?

Christian




More information about the Python-list mailing list