Pythonic way to determine if a string is a number

Floris Bruynooghe floris.bruynooghe at gmail.com
Tue Feb 17 10:12:02 EST 2009


On Feb 16, 12:05 am, Mel <mwil... 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?
>
> Exactly.  A normal program should never do anything more comprehensive than
>
> try:
>     some_function ()
> except StandardError:
>     some_handling ()

Hmm, most places advocate or even outright recommend derriving your
own exceptions from Exception and not from StandardError.  So maybe
your catch-all should be Exception?  In that case you would be
catching warnings though, no idea what influence that has on the
warning system.

Regards
Floris

PS: Does anybody know why StopIterantion derrives from Exception while
GeneratorExit derrives from BaseException?  This could be as annoying/
confusing as Warning.



More information about the Python-list mailing list