New submission from Jerzy jer...@genesilico.pl:
Hi
When I am outputting unicode strings to terminal my script works OK, but
when I redirect it to file I get a crash:
$ python mailing/message_sender.py -l Bia
Białystok
$ python mailing/message_sender.py -l Bia ~/tmp/aaa.txt
Traceback (most
Benjamin Peterson benja...@python.org added the comment:
You have to use an encoding that's not ascii then.
--
nosy: +benjamin.peterson
resolution: - works for me
status: open - closed
___
Python tracker rep...@bugs.python.org
Jerzy jer...@genesilico.pl added the comment:
I know how to make it work. The question is why outputting to file makes
it crush when outputting to terminal does not.
I have never seen $program file behaving in a different way than
$program in any other language
Jerzy Orlowski
Benjamin
Georg Brandl ge...@python.org added the comment:
When output goes to a terminal, Python can determine its encoding. For a
file, it cannot, therefore it refuses to guess.
Also, many programs behave differently when used with redirection;
namely, all those that use `isatty()` to determine if
Jerzy jer...@genesilico.pl added the comment:
Well, I would suggest using the terminal encoding as default one when
redirecting. In my opinion sys.stdin and sys.stdout should always have
the terminal encoding
Alternatively you could make the function sys.setdefaultencoding()
visible to
Martin v. Löwis mar...@v.loewis.de added the comment:
Using the terminal encoding for sys.stdout does not work in the general
case, as a (background) process may not *have* a controlling terminal
(such as a CGI script, a cron job, or a Windows service). That Python
recognizes the terminal
Jerzy jer...@genesilico.pl added the comment:
OK, I give up.
The problem is that one might test a program on terminal and think that
everything is running OK and then spend a reasonable amount of time
trying to find the problem later
Another approach: couldn't utf8 be set as default encoding
Martin v. Löwis mar...@v.loewis.de added the comment:
If you want to switch to a different language, consider switching to
Python 3. There, all strings are Unicode strings, and files opened in
text mode always use the locale encoding.
--
___
Python
Jerzy jer...@genesilico.pl added the comment:
good point!
I will give it a try
Jerzy
Martin v. Löwis wrote:
Martin v. Löwis mar...@v.loewis.de added the comment:
If you want to switch to a different language, consider switching to
Python 3. There, all strings are Unicode strings, and