[Python-ideas] Python 3.x and bytes

Stefan Behnel stefan_ml at behnel.de
Mon May 23 09:19:26 CEST 2011


Nick Coghlan, 23.05.2011 08:02:
> On Mon, May 23, 2011 at 1:46 AM, Stephen J. Turnbull wrote:
>> The question is how far to go with polymorphism, etc.  I think that
>> Nick's urlparse work gets the balance about right, and see only danger
>> in more stringlike bytes (eg, by returning b'b' for b'bytes'[0]).
>> OTOH, there are some changes that might be useful but seem very
>> low-risk, such as a c'b' literal that means 98, not b'b'.
>
> If we did go with an ord() literal, I would actually favour something
> more like 0'b'.
>
> However, as Maciej pointed out off-list, adding a new literal type
> because calls to builtin functions have a relatively high overhead in
> CPython even with constant arguments probably isn't a good idea.
> Better to just write "ord('b')" and use PyPy to make it fast

Even CPython could optimise b'x'[0] into a constant, if people ever find 
this to be a bottleneck.

Stefan




More information about the Python-ideas mailing list