[Tutor] Limitation of int() in converting strings

eryksun eryksun at gmail.com
Mon Dec 17 23:23:04 CET 2012


On Mon, Dec 17, 2012 at 1:00 PM, Alan Gauld <alan.gauld at btinternet.com> wrote:
>
> Python uses its own C code for this.

The important point here is that they use the strtol/strtod interface,
however it's implemented. atoi and atof lack the end pointer argument
that enables raising a ValueError for an incomplete conversion. For
example, strtol("123e9", &end, 10) will merrily return 123, but with
*end == 'e'. I think it's good that Python raises a ValueError in this
case.

    Errors should never pass silently.
    Unless explicitly silenced.

http://www.python.org/dev/peps/pep-0020/


More information about the Tutor mailing list