Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21376

Re: what is best method to set sys.stdout to utf-8?

Date 2012-03-08 07:45 +0100
From Laurent Claessens <moky.math@gmail.com>
Newsgroups comp.lang.python
Subject Re: what is best method to set sys.stdout to utf-8?
References <alpine.DEB.2.00.1203072150450.2657@pebbe> <mailman.497.1331165710.3037.python-list@python.org>
Message-ID <mailman.503.1331189452.3037.python-list@python.org> (permalink)

Show all headers | View raw


> 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.


  I've a naive question : what is wrong with the following system ?

class MyStdOut(object):
     def __init__(self):
         self.old_stdout=sys.stdout
     def write(self,x):
         try:
             if isinstance(x,unicode):
                 x=x.encode("utf8")
         except (UnicodeEncodeError,UnicodeDecodeError):
             sys.stderr.write("This should not happen !")
             raise
         self.old_stdout.write(x)
sys.stdout=MyStdOut()


... well ... a part of the fact that it is much longer ?


Laurent Claessens

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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