Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21363
| 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 | <python-python-list@m.gmane.org> |
| 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 <tjreedy@udel.edu> |
| Subject | Re: what is best method to set sys.stdout to utf-8? |
| Date | Wed, 07 Mar 2012 19:12:59 -0500 |
| References | <alpine.DEB.2.00.1203072150450.2657@pebbe> |
| 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 | <alpine.DEB.2.00.1203072150450.2657@pebbe> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.497.1331165710.3037.python-list@python.org> (permalink) |
| 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 |
Show key headers only | View raw
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
> <class '_io.TextIOWrapper'>, and it's also after using the
> second method.
>
> After using the first method, type(sys.stdout) is changed to
> <class 'encodings.utf_8.StreamWriter'>.
>
> 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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
what is best method to set sys.stdout to utf-8? Peter Kleiweg <pkleiweg@xs4all.nl> - 2012-03-07 21:57 +0100
Re: what is best method to set sys.stdout to utf-8? Terry Reedy <tjreedy@udel.edu> - 2012-03-07 19:12 -0500
Re: what is best method to set sys.stdout to utf-8? Laurent Claessens <moky.math@gmail.com> - 2012-03-08 07:45 +0100
Re: what is best method to set sys.stdout to utf-8? Laurent Claessens <moky.math@gmail.com> - 2012-03-08 07:45 +0100
csiph-web