[Python-ideas] Stop displaying elements of bytes objects as printable ASCII characters in CPython 3
Andrew Barnert
abarnert at yahoo.com
Wed Sep 17 16:51:22 CEST 2014
On Sep 17, 2014, at 4:48, "Eric V. Smith" <eric at trueblade.com> wrote:
> 2. Support a slightly different format specifier. This is what Nick
> proposes above, and I discuss more below. The downside of this is that
> it might be confusing to some users, who see the printf-like formatting
> as some universal standard. It's also hard to document.
The possibility of confusion might be increased if some of the options to bytes look like they should work for str. People will ask, "I can chunk bytes into groups of 4 with /4, why can't I do that with characters when the rest of the format specifier is the same?"
Also, are there other languages that use printf-style specifiers and have %x, with the same options as for int, working for their bytes type? IIRC Go lets you print strings as numbers, as if their UTF-8 representation were a giant big-endian integer; if it's just a consequence of little-used feature in a language that's nobody's first that probably won't add to confusion, but if it's more common and widespread, it might be worth either matching what the others do, or deliberately being as different as possible to prevent confusion. Nick's use of 'h' instead of 'x' and his rearrangement of the fields definitely avoids giving the appearance of being printf-like and any confusion that might cause, while still being able to share fields that make sense. But of course avoiding printf-like-ness means it's a new thing people have to learn. (Of course eventually they want to do something where the format isn't identical to printf, and many of them seem to go to StackOverflow or IRC and complain that there's a "bug in str.format" instead of just glancing at the docs, so maybe making them learn early isn't such a bad thing...)
More information about the Python-ideas
mailing list