[Python-ideas] int('0x3241fca1')

Ned Batchelder ned at nedbatchelder.com
Thu Feb 6 16:13:17 CET 2014


On 2/6/14 8:22 AM, MRAB wrote:
> On 2014-02-06 10:24, Ram Rachum wrote:
>> What do you think about letting the `int` constructor automatically
>> understand the number type without specifying base if given a prefix, so
>> int('0x3414fa') would immediately work without specifying a base of 16?
>>
> The base defaults to 10, but:
>
> >>> int('0x3241fca1', 0)
> 843185313
>
I can't believe how many replies this thread got that overlooked that 
the built-in int() already does exactly what the OP wanted.  Is it too 
much to ask that before you suggest changing the behavior of something, 
that you read *both* paragraphs of the documentation? 
http://docs.python.org/2/library/functions.html#int

--Ned.
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/



More information about the Python-ideas mailing list