Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21375
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!news.le-studio75.com!news.univ-fcomte.fr!not-for-mail |
|---|---|
| From | Laurent Claessens <moky.math@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: what is best method to set sys.stdout to utf-8? |
| Date | Thu, 08 Mar 2012 07:45:32 +0100 |
| Organization | A poorly-installed InterNetNews site |
| Lines | 25 |
| Message-ID | <4F58558C.3000706@gmail.com> (permalink) |
| References | <alpine.DEB.2.00.1203072150450.2657@pebbe> <mailman.497.1331165710.3037.python-list@python.org> |
| NNTP-Posting-Host | acces.univ-fcomte.fr |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.univ-fcomte.fr 1331189442 379 194.57.91.212 (8 Mar 2012 06:50:42 GMT) |
| X-Complaints-To | news@news.univ-fcomte.fr |
| NNTP-Posting-Date | Thu, 8 Mar 2012 06:50:42 +0000 (UTC) |
| Cc | python-list@python.org |
| User-Agent | Mozilla/5.0 (X11; Linux i686; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2 |
| In-Reply-To | <mailman.497.1331165710.3037.python-list@python.org> |
| Xref | csiph.com comp.lang.python:21375 |
Show key headers only | 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 | 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