Yet another unicode WTF

Benjamin Kaplan benjamin.kaplan at case.edu
Fri Jun 5 04:28:13 CEST 2009


On Thu, Jun 4, 2009 at 10:06 PM, Ben Finney
<ben+python at benfinney.id.au<ben%2Bpython at benfinney.id.au>
> wrote:

> Ron Garret <rNOSPAMon at flownet.com> writes:
>
> > Python 2.6.2 on OS X 10.5.7:
> >
> > [ron at mickey:~]$ echo $LANG
> > en_US.UTF-8
> > [ron at mickey:~]$ cat frob.py
> > #!/usr/bin/env python
> > print u'\u03BB'
> >
> > [ron at mickey:~]$ ./frob.py
> > ª
> > [ron at mickey:~]$ ./frob.py > foo
> > Traceback (most recent call last):
> >   File "./frob.py", line 2, in <module>
> >     print u'\u03BB'
> > UnicodeEncodeError: 'ascii' codec can't encode character u'\u03bb' in
> > position 0: ordinal not in range(128)
>
> I get the same behaviour on Debian GNU/Linux, python 2.5.2. It's
> certainly not desirable; the terminal, the shell, and the filesystem are
> all using UTF-8 so it should work fine.
>
> You might be best advised to report this as a bug to the Python bug
> tracker <URL:http://bugs.python.org/>.
>


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.

>
> --
>  \        “I fly Air Bizarre. You buy a combination one-way round-trip |
>  `\    ticket. Leave any Monday, and they bring you back the previous |
> _o__)     Friday. That way you still have the weekend.” —Steven Wright |
> Ben Finney
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090604/8d78473a/attachment.html>


More information about the Python-list mailing list