[Python-ideas] RFC: bytestring as a str representation [was: a new bytestring type?]

Stephen J. Turnbull stephen at xemacs.org
Tue Jan 7 06:05:47 CET 2014


Ethan Furman writes:

 > Having a 7-bit str variant is definitely an interesting idea, but
 > it wouldn't help me and is probably insufficient for network
 > protocols as well.

I'd like evidence for that latter.

 > The binary data I deal with occupies the full 0-255 range,

My proposal deals with such data.  It simply prevents the program from
interpreting the 128-255 range as Unicode characters.  You can still
use regexps etc on the full range 0-255.

 > some of which is actually encoded text (and I decode it before
 > passing it back to the user), some of which is simple binary data,
 > and some of which is simple ASCII (metadata about fields and
 > whatnot).

You're wrong, it would help you.  Encoded text must be decoded, and in
that case it doesn't help you.  Unless you can treat it as a single
ASCII-compatible encoding (eg, this works for ISO-8859 or KOI8), when
the proposal wins for you.  Binary data and pure ASCII, the proposal
wins for you, unless you're worried about spurious recognition of the
binary data as ASCII metadata.  In that last case, again, nothing is
going to help you as it's a domain problem.  My proposal is undefeated
in your use case.



More information about the Python-ideas mailing list