<br><br><div class="gmail_quote">On Thu, Jun 4, 2009 at 10:06 PM, Ben Finney <span dir="ltr"><<a href="mailto:ben%2Bpython@benfinney.id.au">ben+python@benfinney.id.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div class="im">Ron Garret <<a href="mailto:rNOSPAMon@flownet.com">rNOSPAMon@flownet.com</a>> writes:<br>
<br>
> Python 2.6.2 on OS X 10.5.7:<br>
><br>
> [ron@mickey:~]$ echo $LANG<br>
> en_US.UTF-8<br>
> [ron@mickey:~]$ cat frob.py<br>
> #!/usr/bin/env python<br>
> print u'\u03BB'<br>
><br>
> [ron@mickey:~]$ ./frob.py<br>
> ª<br>
> [ron@mickey:~]$ ./frob.py > foo<br>
> Traceback (most recent call last):<br>
>   File "./frob.py", line 2, in <module><br>
>     print u'\u03BB'<br>
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in<br>
> position 0: ordinal not in range(128)<br>
<br>
</div>I get the same behaviour on Debian GNU/Linux, python 2.5.2. It's<br>
certainly not desirable; the terminal, the shell, and the filesystem are<br>
all using UTF-8 so it should work fine.<br>
<br>
You might be best advised to report this as a bug to the Python bug<br>
tracker <URL:<a href="http://bugs.python.org/" target="_blank">http://bugs.python.org/</a>>.<br>
</blockquote><div><br><br>Please don't. This isn't a bug- it's actually a good default. If the user doesn't specify an encoding, Python refuses to guess. In the case of the terminal, python doesn't have to guess because the environment variables give the encoding. When it's writing to a file, there is no way to know what encoding to use so it just sticks with ascii.<br>
</div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>
--<br>
 \        “I fly Air Bizarre. You buy a combination one-way round-trip |<br>
  `\    ticket. Leave any Monday, and they bring you back the previous |<br>
_o__)     Friday. That way you still have the weekend.” —Steven Wright |<br>
<font color="#888888">Ben Finney<br>
</font><div><div></div><div class="h5">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</div></div></blockquote></div><br>