int('2.1') does not work while int(float('2.1')) does

Vineet Jain vineet at eswap.com
Mon Apr 5 21:07:15 EDT 2004


int('2.1') does not work while int(float('2.1')) does. If int can covert a
float object then there is no reason why a float string should not be
converted too.

When I do int('2.1') I get the following error:

>>> a = int('2.0')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): 2.0

This does not seem very pythonic

VJ





More information about the Python-list mailing list