Newbie question about text encoding

Chris Angelico rosuav at gmail.com
Sat Mar 7 12:00:44 EST 2015


On Sun, Mar 8, 2015 at 3:54 AM, Marko Rauhamaa <marko at pacujo.net> wrote:
> You can't operate on file names and text files using Python strings. Or
> at least, you will need to add (nontrivial) exception catching logic.

You can't operate on a JPG file using a Unicode string, nor an array
of integers. What of it? You can't operate on an array of integers
using a dictionary, either. So? How is this a failing of UTF-8?

If you really REALLY can't use the bytes() type to work with something
that is, yaknow, bytes, then you could use an alternative encoding
that has a value for every byte. It's still not Unicode text, so it
doesn't much matter which encoding you use. But it's much better to
use the bytes type to work with bytes. It is not text, so don't treat
it as text.

ChrisA



More information about the Python-list mailing list