Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #74981

Re: Unicode, stdout, and stderr

From Lele Gaifax <lele@metapensiero.it>
Subject Re: Unicode, stdout, and stderr
Date 2014-07-22 09:36 +0200
Organization Nautilus Entertainments
References <mailman.12161.1406009902.18130.python-list@python.org> <53ce0b96$0$29897$c3e8da3$5496439d@news.astraweb.com> <lql32r$d5$1@ger.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.12169.1406014585.18130.python-list@python.org> (permalink)

Show all headers | View raw


"Frank Millman" <frank@chagford.com> writes:

> "Steven D'Aprano" <steve@pearwood.info> wrote in message 
> news:53ce0b96$0$29897$c3e8da3$5496439d@news.astraweb.com...
>> I would be surprised if that were the case, but I don't have a Windows
>> box to test it. Try this:
>>
>>
>> import sys
>> print(x, file=sys.stderr)  # I expect this will fail
>
> It does not fail.

Effectively it does not, but for some reason it actually print the
repr() of the string.

>> print(repr(x), file=sys.stdout)  # I expect this will succeed
>>
>
> It fails.

This surprises me as well, why does it fail here?

>>> repr('\u2119')
"'\u2119'"
>>> print(repr('\u2119'))
Traceback ... UnicodeEncodeError ...

On GNU/Linux, I get:

>>> repr('\u2119')
"'ℙ'"
>>> print(repr('\u2119'))
'ℙ'

Uhm, it must be related to the fact that on Py3 the repr() of something
is a unicode object too, so the output machinery tries to encode it to
the output encoding.... Still, I miss the difference between stdout and
stderr (both are cp437, accordingly to sys.xxx.encoding).

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
lele@metapensiero.it  |                 -- Fortunato Depero, 1929.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Unicode, stdout, and stderr "Frank Millman" <frank@chagford.com> - 2014-07-22 08:18 +0200
  Re: Unicode, stdout, and stderr wxjmfauth@gmail.com - 2014-07-21 23:54 -0700
  Re: Unicode, stdout, and stderr Steven D'Aprano <steve@pearwood.info> - 2014-07-22 06:58 +0000
    Re: Unicode, stdout, and stderr "Frank Millman" <frank@chagford.com> - 2014-07-22 09:15 +0200
    Re: Unicode, stdout, and stderr Lele Gaifax <lele@metapensiero.it> - 2014-07-22 09:36 +0200
    Re: Unicode, stdout, and stderr Akira Li <4kir4.1i@gmail.com> - 2014-07-23 05:01 +0400
      Re: Unicode, stdout, and stderr wxjmfauth@gmail.com - 2014-07-23 00:35 -0700
  Re: Unicode, stdout, and stderr wxjmfauth@gmail.com - 2014-07-22 00:07 -0700

csiph-web