srtring to int question
Jim Richardson
warlock at eskimo.com
Sun Aug 13 02:16:35 EDT 2000
On Sat, 12 Aug 2000 22:46:03 -0400,
Darrell Gallion, in the persona of <darrell at dorb.com>,
brought forth the following words...:
>Dooo@!
>Those examples make more sense like this.
>The re prevents bad things from being input into eval.
>
>def convert(s):
> try:
> x = int(s)
> except:
> print "Not a number"
> return None
> return x
>
>def convert(s):
> try:
> assert(re.match("\s*\d+",s))
> x=eval(s,{},{})
> except:
> print "Not a number"
> return None
> return x
>
Thanks to all who posted, try seems to be what I needed, (eval looks more
complicated than I need at the moment, especially wrt the security issues.
But it is something I will read the docs for :)
--
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