srtring to int question

Olivier Dagenais olivierS.dagenaisP at canadaA.comM
Sun Aug 13 01:20:00 EDT 2000


Since everybody else mentionned exceptions, I will mention two other ideas:
filter out all non-digits (using the built-in filter function) or use "in":

if ( (lowercase + uppercase) in user_string ):
    # invalid string!

Unless I'm too tired to notice something???

--
----------------------------------------------------------------------
Olivier A. Dagenais - Carleton University - Computer Science III


"Jim Richardson" <warlock at eskimo.com> wrote in message
news:slrn8pbuah.1t3.warlock at gargoyle.myth...
> For various reasons, I have written a small bit of python code to
> take a 1-3 julian day, and return the day-month form. It works
> ok mostly (available at
http://www.eskimo.com/~warlock/freesoft/julian_py.tgz)
>  OK, the question, I use raw_input to poll for the julian day, and
> then convert to int via int, but how do I check that the value from
raw_input
> is "intable"? that is, it works fine if I pass a number, but if I type in
> non-numerical characters, [a-zA-Z!@# etc] then the code errors on the
> int() function. Any pointers? thanks
>
> --
> Jim Richardson
> Anarchist, pagan and proud of it
> WWW.eskimo.com/~warlock
> Linux, because life's too short for a buggy OS.
>





More information about the Python-list mailing list