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: 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 Subject: Re: Unicode, stdout, and stderr Date: Tue, 22 Jul 2014 09:36:10 +0200 Organization: Nautilus Entertainments References: <53ce0b96$0$29897$c3e8da3$5496439d@news.astraweb.com> 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 "Frank Millman" writes: > "Steven D'Aprano" 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.