Pythonic way to determine if a string is a number

Roy Smith roy at panix.com
Mon Feb 16 03:35:20 CET 2009


In article <gnaak5$1nek$1 at services.telesweet.net>,
 Mel <mwilson at the-wire.com> wrote:

> Christian Heimes wrote:
> > Roy Smith wrote:
> 
> >> 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?

Absolutely.  Let's take my example -- you're writing software for a Mars 
Rover.  I have no idea how you might get a MemoryError, but let's say you 
do.  Which would you rather do, perform a system reset, or print a stack 
trace and wait for a friendly Martian to come along and reboot you?

You may think I'm being silly, but I'm dead serious.  The many layers of 
"It's impossible for this to happen, but if it does let's do something to 
try and recover" processing saved that mission several times over.  In some 
applications, there's no such thing as "halt".



More information about the Python-list mailing list