Odd ValueError using float

Chris Angelico rosuav at gmail.com
Sat Mar 14 18:20:18 EDT 2015


On Sun, Mar 15, 2015 at 9:09 AM, Cameron Simpson <cs at zip.com.au> wrote:
> 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:

Possibly missing the bit where decval looks to be a string containing
the one character U+0034 DIGIT FOUR, and then suddenly has a whole
mess of extra characters. :)

Check out the fenx stuff, as that's the only non-stdlib code you have.
Maybe it calls on a C extension module somewhere deep inside it.

ChrisA



More information about the Python-list mailing list