Frank Millman wrote:

> If I really wanted to be 100% safe, how about this -
> 
>     def get_int(s):
>         if '.' in s:
>             num, dec = s.split('.', 1)
>             if dec != '':
>                 if int(dec) != 0:
>                     raise ValueError('Invalid literal for int')
>             return int(num)
>         return int(s)

Consider what happens if you pass s = "42.-0".


-- 
Steven

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to