Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Peter Otten <__peter__@web.de> Newsgroups: comp.lang.python Subject: Re: Unicode failure Date: Sat, 05 Dec 2015 00:03:35 +0100 Organization: None Lines: 32 Message-ID: References: <20151204130738.76313c43@imp> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Trace: news.uni-berlin.de 3Lxi5v+M+hQSUSwNWqjBownT4r94dfkp9v1BtcVdpYog== 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; '"""': 0.05; 'sys': 0.05; '-*-': 0.07; 'locale': 0.07; 'skip:/ 10': 0.07; 'utf-8': 0.07; 'coding:': 0.09; 'encode': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'true),': 0.09; 'python': 0.10; 'encoding': 0.15; 'codec': 0.16; 'missing?': 0.16; 'ordinal': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'received:t-ipconnect.de': 0.16; 'stuff.': 0.16; 'subject:Unicode': 0.16; 'wrote:': 0.16; 'script.': 0.18; 'skip:l 30': 0.18; '(see': 0.20; 'seems': 0.23; 'import': 0.24; '(most': 0.24; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.26; 'used,': 0.27; 'page.': 0.28; 'ansi': 0.29; 'windows,': 0.29; 'character': 0.29; 'code': 0.30; "can't": 0.32; 'url:python': 0.33; 'stream': 0.33; 'traceback': 0.33; 'file': 0.34; 'platforms,': 0.35; 'unicode': 0.35; 'url:dev': 0.35; 'skip:p 30': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'method': 0.37; 'received:org': 0.37; 'thought': 0.37; 'to:addr:python.org': 0.40; 'mark': 0.40; 'still': 0.40; 'received:de': 0.40; 'skip:u 10': 0.61; '(that': 0.63; 'here': 0.66; '3.4': 0.84 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: p57bd8cdc.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:100020 D'Arcy J.M. Cain wrote: > I thought that going to Python 3.4 would solve my Unicode issues but it > seems I still don't understand this stuff. Here is my script. > > #! /usr/bin/python3 > # -*- coding: UTF-8 -*- > import sys > print(sys.getdefaultencoding()) > print(u"\N{TRADE MARK SIGN}") > > And here is my output. > > utf-8 > Traceback (most recent call last): > File "./g", line 5, in > print(u"\N{TRADE MARK SIGN}") > UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in > position 0: ordinal not in range(128) > > What am I missing? """The character encoding is platform-dependent. Under Windows, if the stream is interactive (that is, if its isatty() method returns True), the console codepage is used, otherwise the ANSI code page. Under other platforms, the locale encoding is used (see locale.getpreferredencoding()). """ https://docs.python.org/dev/library/sys.html#sys.stdout