[Python-ideas] Fixing the Python 3 bytes constructor
Philipp A.
flying-sheep at web.de
Fri Mar 28 18:31:58 CET 2014
2014-03-28 18:17 GMT+01:00 Guido van Rossum <guido at python.org>:
> On Fri, Mar 28, 2014 at 10:06 AM, Benjamin Peterson <benjamin at python.org>wrote:
>
>> I agree. We would add a method that iterates over single bytes as bytes
>> objects instead of integers.
>>
>
> Now that's making sense.
>
even if some people don’t like it, the iterating over bytes objects makes
perfect sense.
in every statically typed language, a byte is most commonly repesented as
an integer in the range [0,255].
the annoyance has two sources:
1.
python 2 byte strings (aka “native strings”) behaved like that (and
unicode strings behave like that because python has no char type)
2.
byte strings are represented like strings, including ascii-compatible
parts as if they were ASCII text.
therefore, paople think single bytes would be something akin to chars
instead of simply integers from 0 to 255.
b'a'[0] == 97 looks strange, but let’s not forget that it’s actually b'\x61'[0]
== 0x61
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140328/69b70f27/attachment-0001.html>
More information about the Python-ideas
mailing list