Unhelpful error message

Jon Ribbens jon+usenet at unequivocal.eu
Tue Jun 6 14:38:25 EDT 2017


On 2017-06-06, Peter Otten <__peter__ at web.de> wrote:
> ...but not the empty string:
>
>>>> float("")
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: could not convert string to float: 
>
> Maybe there were some backward compatibility concerns that I lack the 
> fantasy to imagine.

It's a little odd, PyFloat_FromString just calls:

    PyErr_Format(PyExc_ValueError,
                 "could not convert string to float: %R", v);

which should be appending the repr() of the argument to the error
message, and there's no code I can see anywhere that would be
special-casing the empty string and avoiding inserting "''".



More information about the Python-list mailing list