Wrapping stdout in a codec

JKPeck JKPeck at gmail.com
Wed Oct 24 19:59:32 EDT 2007


On Oct 22, 12:20 am, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> On Mon, 22 Oct 2007 02:41:17 +0000, JKPeck wrote:
> > We want to wrap the stdout device in a codec in order to decode output
> > transparently according to a particular code page (which might not be
> > the system code page).  However, codec.open requires a filename, and
> > stdout may be a tty or otherwise anonymous.  How can we accomplish
> > this wrapping?
>
> The `codecs` module has more than just the `codecs.open()` function.  Try
> something like this::
>
>   sys.stdout = codecs.getwriter('utf-8')(sys.stdout)
>
> Ciao,
>         Marc 'BlackJack' Rintsch

Thanks, codecs.getwriter is just the ticket.  Our app may not be
running in the system encoding, so the file system encoding is not
appropriate.




More information about the Python-list mailing list