[Tutor] os.urandom()
Dave Angel
davea at ieee.org
Tue Aug 10 06:24:00 CEST 2010
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.
>
>
More information about the Tutor
mailing list