Path: csiph.com!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'method,': 0.05; 'received:verizon.net': 0.07; 'terry': 0.07; 'python': 0.08; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:method': 0.09; 'utf-8': 0.09; 'method.': 0.15; 'partly': 0.16; 'reedy': 0.16; 'replaces': 0.16; 'subject:set': 0.16; 'sys.stdout': 0.16; 'wrote:': 0.18; 'jan': 0.19; 'header:In-Reply- To:1': 0.22; 'changed': 0.23; 'guess': 0.26; 'module': 0.26; 'script': 0.28; 'second': 0.28; 'seem': 0.29; 'pm,': 0.29; 'remains': 0.30; 'subject:?': 0.31; 'there': 0.33; 'header:User- Agent:1': 0.33; 'header:X-Complaints-To:1': 0.34; 'latter': 0.34; 'to:addr:python-list': 0.35; 'two': 0.36; 'received:org': 0.36; 'using': 0.37; 'should': 0.38; 'to:addr:python.org': 0.40; 'back': 0.60; 'more': 0.61; 'subject:best': 0.67; 'start-up,': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Terry Reedy Subject: Re: what is best method to set sys.stdout to utf-8? Date: Wed, 07 Mar 2012 19:12:59 -0500 References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: pool-74-109-121-73.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:8.0) Gecko/20111105 Thunderbird/8.0 In-Reply-To: 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: 24 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331165710 news.xs4all.nl 6942 [2001:888:2000:d::a6]:42835 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21363 On 3/7/2012 3:57 PM, Peter Kleiweg wrote: > > In Python 3, there seem to be two ways to set sys.stdout to > utf-8 after the script has started: > > sys.stdout = codecs.getwriter('utf-8')(sys.stdout.detach()) > > sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding='utf-8') > > I guess the second is better. At start-up, type(sys.stdout) is > , and it's also after using the > second method. > > After using the first method, type(sys.stdout) is changed to > . > > Should I always use the second method? I would. The io module is more recent an partly replaces codecs. The latter remains for back compatibility and whatever it can do that io cannot. -- Terry Jan Reedy