Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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; 'sys': 0.05; 'none:': 0.07; 'subject:when': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:80.91.229.12': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'received:lo.gmane.org': 0.09; 'utf-8': 0.09; 'thanks!': 0.14; '-*-': 0.16; 'adam': 0.16; 'coding:': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:t-dialin.net': 0.16; 'stdout': 0.16; 'subject:directly': 0.16; 'sys.stdout': 0.16; 'wrote:': 0.18; '>>>': 0.18; 'subject:not': 0.21; 'from:addr:web.de': 0.23; 'guess': 0.26; 'import': 0.27; 'print': 0.29; 'writer': 0.30; 'rather': 0.33; 'header:X-Complaints-To:1': 0.33; 'to:addr:python-list': 0.34; 'force': 0.34; 'something': 0.35; 'but': 0.37; 'received:org': 0.38; 'to:addr:python.org': 0.40; 'move': 0.40; 'within': 0.60; 'subject:but': 0.67; 'become': 0.69; 'funk': 0.84; 'otten': 0.84; 'subject:printing': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: UnicodeEncodeError when piping stdout, but not when printing directly to the console Date: Fri, 06 Jan 2012 10:34:10 +0100 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Gmane-NNTP-Posting-Host: p5084a0cb.dip.t-dialin.net X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1325842466 news.xs4all.nl 6968 [2001:888:2000:d::a6]:50640 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:18593 Adam Funk wrote: > On 2012-01-04, Peter Otten wrote: > >> Adam Funk wrote: > >>> How can I force python (preferably within my python program, rather >>> than having to set something externally) to treat stdout as UTF-8? >> >> >> $ cat force_utf8.py >> # -*- coding: utf-8 -*- >> import sys >> >> if sys.stdout.encoding is None: >> import codecs >> writer = codecs.getwriter("utf-8") >> sys.stdout = writer(sys.stdout) >> >> print u"Ähnlich üblich nötig" > > That's great, thanks! > > I guess issues like this will magically go away when I eventually move > to Python 3? Not "magically", but UTF-8 has become the default encoding...