4 ms·
> I really like that Python 2's str could hold arbitrary binary data Python 3's str can also hold arbitrary binary data. That ability was introduced in PEP 383
by slavik81 7y ago
> I really like that Python 2's str could hold arbitrary binary data
Python 3's str can also hold arbitrary binary data. That ability was introduced in PEP 383.
- excessive 7y agoThank you for telling me about this - I didn't know they did that... My first thought as I started reading the PEP was, "Why did they bother adding the 'bytes' type if 'str' is just going to be able to hold everything anyways?" After looking at more of it though, it seems like they're storing the binary octets as code points in one of several internal Unicode representations. Moreover, they're abusing (reusing?) the range of code points reserved for 16 bit surrogate pairs, but only using the low half of the pair. This is all clever in the bad way. This seems like a real lack of taste to me, and I doubt the Guido from 1991 would've found it acceptable to have 'str', 'bytes', and 'bytearray' the way they are. (Let's ignore 'buffer' became 'memoryview' for now...) It used to be a simple and elegant language.