tuple __repr__ non-ascii characters

Chris Angelico rosuav at gmail.com
Thu Oct 31 11:06:45 EDT 2013


On Fri, Nov 1, 2013 at 1:59 AM, Yaşar Arabacı <yasar11732 at gmail.com> wrote:
> Is there a better way to handle this problem?

There is, but I don't know how easy it'll be. In Python 3, the repr of
a tuple will show Unicode strings as Unicode. :)

For what you're showing there, I'm not actually quite sure what's
going on. Is the string a Unicode string, or a byte string? If it's a
byte string (which I suspect, since it's coming up as \xfe and the
character you're showing us isn't U+00FE), then you have to worry
about encodings. If you're using it to store non-ASCII data, you
probably want to be using a Unicode string:

a = u"yaşar"

The best solution is definitely to move to Python 3, though - if you
can. Do you have much code to migrate, or are you starting fresh? Are
there any libraries/modules that you need that don't support Py3?

ChrisA



More information about the Python-list mailing list