Odd ValueError using float
Cameron Simpson
cs at zip.com.au
Sat Mar 14 18:09:07 EDT 2015
On 14Mar2015 08:28, Emile van Sebille <emile at fenx.com> wrote:
>It ran almost to completion before generating the error again --
>
>(Pdb) decval
>'4'
>(Pdb) type(decval)
><type 'str'>
>(Pdb) len(decval)
>1
>(Pdb) int(decval)
>*** ValueError: invalid literal for int() with base 10: '41.700000000000003'
>
>So there's still something amiss.
Am I missing something obvious here? int() likes only ints, not floats:
Python 2.7.9 (default, Dec 13 2014, 15:13:49)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> int('1.3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.3'
Python 3.4.3 (default, Feb 27 2015, 00:22:26)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> int('1.3')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '1.3'
Cheers,
Cameron Simpson <cs at zip.com.au>
C++ also supports the notion of *friends*: cooperative classes that are
permitted to see each other's private parts.
- Grady Booch, "Object Oriented Design with Applications"
More information about the Python-list
mailing list