Steven D'Aprano wrote:
On Mon, 9 Aug 2010 11:51:34 pm you wrote:
<snip>
(Context:  Python 3.x, where strings are unicode.)


repr() returns the string representation, not the byte representation. Try this:

That's what I was missing. Somehow I assumed it was converting to byte strings.

I had assumed that it reverted to /uxxxx or /Uxxxxxxxx whenever a character was outside the ASCII range. That would be a direct analog to what seems to happen on byte strings. Does it only escape newlines and single quotes ?

a = chr(300)
b = repr(a)

My prediction is that it will succeed, and not fail. Then try this:

print(a)

My prediction is that it will fail with UnicodeEncodeError. It is is your terminal that can't display arbitrary Unicode characters, because your terminal have a weird encoding set. Fix the terminal, and you won't have the problem:

Any suggestions how to fix the Windows console to interpret utf8?
<snip>
FWIW, my sys.stdout.encoding is cp437.


Well, there's your problem.


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to