"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.
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
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
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
> 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
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
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
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:
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
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
10 matches
Mail list logo