srtring to int question

Darrell Gallion darrell at dorb.com
Sat Aug 12 22:46:03 EDT 2000


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







More information about the Python-list mailing list