[Python-ideas] Stop displaying elements of bytes objects as printable ASCII characters in CPython 3

Stephen J. Turnbull stephen at xemacs.org
Thu Sep 18 06:21:56 CEST 2014


Andrew Barnert writes:

 > 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?"

Isn't the answer to that kind of question "because you haven't written
the PEP yet?"

Or "Repeat after me, 'bytes are not str' ... Very good, now do a set
of 100 before each meal for a week."  After all, there are things you
can do with integer or float formats that you can't do with str and
vice versa.

bytes are indeed very similar to str as streams of code units (octets
vs. characters), but the specific usages for human-oriented text
(including such unnatural languages as C and Perl) require some
differences in semantics.  The sooner people get comfortable with
that, the better, of course, but I don't think the language should be
prevented from evolving because many people are going to take a while
to get the difference and its importance.

 > (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...)

Obviously, given the snotty remark above, I sympathize.  But I doubt
it's really going to help that.  It's just going to give them one more
thing to complain about.<wink/>



More information about the Python-ideas mailing list