Re: pipeline encoding

2007-12-07 Thread Tomasz Toczyski
"Martin v. Löwis": > Not a command line option. However, you can wrap sys.stdout with a > stream that automatically performs an encoding. If all your print > statements output Unicode strings, you can do > > sys.stdout = codecs.getwriter("utf-8")(sys.stdout) It is the best solution for me. Thanks.

Re: pipeline encoding

2007-12-06 Thread Gabriel Genellina
En Thu, 06 Dec 2007 14:13:04 -0300, Tomasz Toczyski <[EMAIL PROTECTED]> escribió: > My locale is set to UTF-8. The command: > python -c "print u'\u03A9'" > gives me the desired result and doesn't produce any error. Because in this case stdout is bound to your terminal and Python can ask the O

Re: pipeline encoding

2007-12-06 Thread Peter Otten
Tomek Toczyski wrote: > Diez B. Roggisch: > >> >> Python tries and guesses the stdout-encoding based on the terminal >> settings. So the first print works. >> >> However, piping to a file means that it can't do so, because it doesn't >> (and shouldn't) make any assumptions on the output encodin

Re: pipeline encoding

2007-12-06 Thread Rob Wolfe
Tomek Toczyski <[EMAIL PROTECTED]> writes: > Are there any command line option for telling python what encoding to > use for stdout? > > To be honest I have a more complicated program than the example that I > have presented - there are many print commands inside and it is not > very feasible for

Re: pipeline encoding

2007-12-06 Thread Martin v. Löwis
> Are there any command line option for telling python what encoding to > use for stdout? Not a command line option. However, you can wrap sys.stdout with a stream that automatically performs an encoding. If all your print statements output Unicode strings, you can do sys.stdout = codecs.getwrite

Re: pipeline encoding

2007-12-06 Thread Diez B. Roggisch
Tomek Toczyski schrieb: > Diez B. Roggisch: > >> >> Python tries and guesses the stdout-encoding based on the terminal >> settings. So the first print works. >> >> However, piping to a file means that it can't do so, because it >> doesn't (and shouldn't) make any assumptions on the output encodi

Re: pipeline encoding

2007-12-06 Thread Tomek Toczyski
Diez B. Roggisch: > > Python tries and guesses the stdout-encoding based on the terminal > settings. So the first print works. > > However, piping to a file means that it can't do so, because it doesn't > (and shouldn't) make any assumptions on the output encoding desired - > after all, it migh

Re: pipeline encoding

2007-12-06 Thread Rob Wolfe
Tomasz Toczyski <[EMAIL PROTECTED]> writes: > My locale is set to UTF-8. The command: > python -c "print u'\u03A9'" > gives me the desired result and doesn't produce any error. > > But when I want to redirect the output to a file I invoke: > python -c "print u'\u03A9'" > file.txt > I get an error:

Re: pipeline encoding

2007-12-06 Thread Diez B. Roggisch
Tomasz Toczyski schrieb: > My locale is set to UTF-8. The command: > python -c "print u'\u03A9'" > gives me the desired result and doesn't produce any error. > > But when I want to redirect the output to a file I invoke: > python -c "print u'\u03A9'" > file.txt > I get an error: > > File "", line

pipeline encoding

2007-12-06 Thread Tomasz Toczyski
My locale is set to UTF-8. The command: python -c "print u'\u03A9'" gives me the desired result and doesn't produce any error. But when I want to redirect the output to a file I invoke: python -c "print u'\u03A9'" > file.txt I get an error: File "", line 1, in UnicodeEncodeError: 'ascii' codec c