[Tutor] try/except question

Magnus Lyckå magnus@thinkware.se
Tue May 20 16:59:01 2003


Jeff made a number of good points as usual, but I have some more to add.

At 14:31 2003-05-20 -0500, Isaac Hall wrote:
>try:
>    a=eval(string)

Don't you want a = int(string) here?

Why else do you think you might get an OverflowError?
eval('99999999999999999999') will simply return a long.

>except(OverflowError):
>    a=long(string)
>except(NameError):
>    a=string
>
>return a
>
>The problem I am having is that this still crashes/exits on a NameError.

Do you really have a variable called "string"?

If you don't, you will get a NameError in the try block, go to the last
except block, and get a new NameError there... :)


--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program