Re: UnicodeEncodeError when piping stdout, but not when printing directly to the console

2012-01-06 Thread Adam Funk
On 2012-01-06, Peter Otten wrote: > Adam Funk wrote: > >> On 2012-01-04, Peter Otten wrote: >> >>> Adam Funk wrote: >> How can I force python (preferably within my python program, rather than having to set something externally) to treat stdout as UTF-8? >>> >>> >>> $ cat force_utf8.py

Re: UnicodeEncodeError when piping stdout, but not when printing directly to the console

2012-01-06 Thread Peter Otten
Adam Funk wrote: > On 2012-01-04, Peter Otten wrote: > >> Adam Funk wrote: > >>> How can I force python (preferably within my python program, rather >>> than having to set something externally) to treat stdout as UTF-8? >> >> >> $ cat force_utf8.py >> # -*- coding: utf-8 -*- >> import sys >> >>

Re: UnicodeEncodeError when piping stdout, but not when printing directly to the console

2012-01-06 Thread Adam Funk
On 2012-01-04, Peter Otten wrote: > Adam Funk wrote: >> How can I force python (preferably within my python program, rather >> than having to set something externally) to treat stdout as UTF-8? > > > $ cat force_utf8.py > # -*- coding: utf-8 -*- > import sys > > if sys.stdout.encoding is None: >

Re: UnicodeEncodeError when piping stdout, but not when printing directly to the console

2012-01-04 Thread Peter Otten
Adam Funk wrote: > (I'm using Python 2.7.2+ on Ubuntu.) > > When I'm running my program in an xterm, the print command with an > argument containing unicode works fine (it correctly detects my UTF-8 > environment). But when I run it with a pipe or redirect to a file (| > or >), unicode strings f