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

Ram Rachum ram at rachum.com
Thu Feb 6 13:30:30 CET 2014


Yep, that's what I meant :)


On Thu, Feb 6, 2014 at 2:28 PM, spir <denis.spir at gmail.com> wrote:

> On 02/06/2014 11:24 AM, 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?
>>
>
> Do you mean int(numeral), where numeral is a *variable* string, with a
> python base prefix? (Else, just type in the constant 0x3414fa ;-) If yes,
> then I find it a good idea. When int() is used to decode variable numerals,
> it could/should/would decode all correct python numeral notations.
>
> Note that int() also does not decode 'e' postfixes:
>
> Python 3.3.2+ (default, Oct  9 2013, 14:50:09)
> [GCC 4.8.1] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>
>> int(123e2)
>>>>
>>> 12300
>
>> int("123e2")
>>>>
>>> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> ValueError: invalid literal for int() with base 10: '123e2'
>
> But float() does:
>
>  float(-1.23e4)
>>>>
>>> -12300.0
>
>> float("-1.23e4")
>>>>
>>> -12300.0
>
> !
>
> After all, it's just a question of practical notational conventions (we
> don't use "hundred and twenty-three" or "CXXIII" or "v^^^^^v^^"). Python's
> own decoding builtins should be consistent with its own choice of notations.
>
> d
> _______________________________________________
> 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/
>
> --
>
> --- You received this message because you are subscribed to a topic in the
> Google Groups "python-ideas" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/
> topic/python-ideas/RKQviWz9BYk/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> python-ideas+unsubscribe at googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140206/88ae3412/attachment-0001.html>


More information about the Python-ideas mailing list