Problems with conversion of values in strings to integers
news at yebu.de
Mon Oct 6 14:06:52 CEST 2003
Jørgen Cederberg wrote:
> using Python 2.2.1 on Windows and QNX I'm having trouble understandig
> why int() raises a ValueError exception upon converting strings.
> >>> int('-10')
> >>> int('10')
> >>> int(10.1)
> >>> int('10.1')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> ValueError: invalid literal for int(): 10.1
> This is quite frustating. The only solution I can see is to do:
> >>> int(float('10.1'))
depending on what you actually want,
might be appropriate.
But if you really want the "floor"-value,
nothing is wrong with your approach.
More information about the Python-list