"More About Unicode in Python 2 and 3"

Dan Stromberg drsalists at gmail.com
Sun Jan 5 21:37:40 EST 2014


On Sun, Jan 5, 2014 at 4:46 PM, Ethan Furman <ethan at stoneleaf.us> wrote:
> While I don't agree with his assessment of Python 3 in total, I definitely
> feel his pain with regards to bytestrings in Py3 -- because they don't
> exist.  'bytes' /looks/ like a bytestring, but really it's just a bunch of
> integers:
>
> --> b'abc
> 'b'abc'
> --> b'abc'[1]
> 98
>
> Maybe for 3.5 somebody *cough* will make a bytestring type for those of us
> who have to support the lower-level protocols...

I don't see anything wrong with the new bytes type, including the
example above.  I wrote a backup program that used bytes or str's (3.x
or 2.x respectively), and they both worked fine for that.  I had to
code around some limited number of surprises, but they weren't
substantive problems, they were just differences.

The argument seems to be "3.x doesn't work the way I'm accustomed to,
so I'm not going to use it, and I'm going to shout about it until
others agree with me."  And yes, I read Armin's article - it was
pretty long....

Also, I never once wrote a program to use 2.x's unicode type.  I
always used str.  It was important to make str handle unicode, to get
people (like me!) to actually use unicode.

Two modules helped me quite a bit with backshift, the backup program I
mentioned:
http://stromberg.dnsalias.org/~dstromberg/backshift/documentation/html/python2x3-module.html
http://stromberg.dnsalias.org/~dstromberg/backshift/documentation/html/bufsock-module.html

python2x3 is tiny, and similar in spirit to the popular six module.

bufsock is something I wrote years ago that enables consistent I/O on
sockets, files or file descriptors; 2.x or 3.x.

HTH



More information about the Python-list mailing list