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


Groups > comp.lang.python > #74981

Re: Unicode, stdout, and stderr

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'output': 0.05; 'string.': 0.05; 'sys': 0.07; 'tries': 0.07; 'encode': 0.09; 'here?': 0.09; 'received:151': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'wrote': 0.14; 'windows': 0.15; '(both': 0.16; 'emanuele': 0.16; 'fails.': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'repr()': 0.16; 'skip:n 50': 0.16; 'stderr': 0.16; 'stdout': 0.16; 'subject:Unicode': 0.16; 'surprises': 0.16; 'not,': 0.20; '>>>': 0.22; 'import': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'unicode': 0.24; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'related': 0.29; 'writes:': 0.31; 'something': 0.35; 'case,': 0.35; 'test': 0.35; 'but': 0.35; 'to:addr:python-list': 0.38; 'fact': 0.38; 'expect': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'skip:u 10': 0.60; 'che': 0.60; 'effectively': 0.66; 'between': 0.67; 'miss': 0.74; 'fail.': 0.84; 'quando': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Lele Gaifax <lele@metapensiero.it>
Subject Re: Unicode, stdout, and stderr
Date Tue, 22 Jul 2014 09:36:10 +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>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host 151.62.51.3
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/24.3.92 (gnu/linux)
Cancel-Lock sha1:j4gZqL1lPBK58LJI65iqUdw7+eo=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12169.1406014585.18130.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1406014585 news.xs4all.nl 2852 [2001:888:2000:d::a6]:33407
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:74981

Show key headers only | 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