Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!hq-usenetpeers!hq-usenetpeers.eweka.nl!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed3a.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; 'url:pypi': 0.03; 'win32': 0.03; 'handler': 0.05; 'important,': 0.07; 'sys': 0.07; 'utf-8': 0.07; 'e.g.,': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'url:github': 0.09; 'windows,': 0.09; 'python': 0.11; 'gui': 0.12; 'wrote': 0.14; 'windows': 0.15; 'attribute.': 0.16; 'fails.': 0.16; 'ides': 0.16; 'idlelib': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'skip:n 50': 0.16; 'stderr': 0.16; 'stdout': 0.16; 'subject:Unicode': 0.16; 'sys.stderr': 0.16; 'url:issues': 0.16; 'alpha': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; '(in': 0.22; 'install': 0.23; 'header:User-Agent:1': 0.23; 'error': 0.23; 'this:': 0.26; 'header:X-Complaints-To:1': 0.27; 'skip:( 20': 0.30; "skip:' 10": 0.31; 'writes:': 0.31; 'run': 0.32; 'linux': 0.33; 'url:python': 0.33; 'could': 0.34; 'case,': 0.35; 'test': 0.35; 'but': 0.35; 'there': 0.35; '+0200,': 0.36; 'url:org': 0.36; 'feedback': 0.38; 'message-id:@gmail.com': 0.38; 'server': 0.38; 'to:addr:python-list': 0.38; 'expect': 0.39; 'explain': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'more': 0.64; 'between': 0.67; 'frank': 0.68; 'jul': 0.74; '2014,': 0.84; 'fail.': 0.84; 'received:89': 0.85 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Akira Li <4kir4.1i@gmail.com> Subject: Re: Unicode, stdout, and stderr Date: Wed, 23 Jul 2014 05:01:08 +0400 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: 89.169.229.68 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:AaqkSrjBMNPA2txpICKq+NTFfSM= 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: 81 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1406077282 news.xs4all.nl 2836 [2001:888:2000:d::a6]:42983 X-Complaints-To: abuse@xs4all.nl X-Received-Bytes: 5241 X-Received-Body-CRC: 3084042359 Xref: csiph.com comp.lang.python:75045 "Frank Millman" writes: > "Steven D'Aprano" wrote in message > news:53ce0b96$0$29897$c3e8da3$5496439d@news.astraweb.com... >> On Tue, 22 Jul 2014 08:18:08 +0200, Frank Millman wrote: >> >>> This is not important, but I would appreciate it if someone could >>> explain the following, run from cmd.exe on Windows Server 2003 - >>> >>> C:\>python >>> Python 3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 >>> bit (In >>> tel)] on win32 >>> Type "help", "copyright", "credits" or "license" for more information. >>>>>> x = '\u2119' >>>>>> x # this uses stderr >>> '\u2119' >> >>> It seems that there is a difference between writing to stdout and >>> writing to stderr. >> >> 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. >> print(repr(x), file=sys.stdout) # I expect this will succeed > > It fails. Check sys.stderr.errors attribute. Try >>> import sys >>> x = '\u2119' >>> x.encode(sys.stderr.encoding, sys.stderr.errors) # succeed >>> x.encode(sys.stdout.encoding, sys.stdout.errors) # fail sys.stderr uses 'backslashreplace' error handler that is why you see \u2119 instead of ℙ. On Linux with utf-8 locale: >>> print('\u2119') ℙ >>> print(repr('\u2119')) 'ℙ' >>> print(ascii('\u2119')) '\u2119' >>> '\u2119' 'ℙ' >>> repr('\u2119') "'ℙ'" >>> ascii('\u2119') "'\\u2119'" On Windows, try https://pypi.python.org/pypi/win_unicode_console C:\> pip install win-unicode-console C:\> py -i -m run It is alpha but your feedback may improve it https://github.com/Drekin/win-unicode-console/issues If you could also use a GUI console e.g.: C:\> py -3 -m idlelib Or http://ipython.org/notebook.html There are many other IDEs for Python e.g., http://stackoverflow.com/q/81584/what-ide-to-use-for-python -- Akira