[Python-Dev] Unicode howto in the works - feedback appreciated
Martin v. Loewis
martin@v.loewis.de
01 May 2002 21:21:47 +0200
Gustavo Niemeyer <niemeyer@conectiva.com> writes:
> Will "print s.encode('iso-8859-1')" work for everybody? If not, how is
> it better than doing it implicitly in site.py?
It won't work for everybody: it will only work if the terminal's (*)
encoding is latin-1.
For printing to the terminal, using the locale's encoding is a good
guess (**). That does not mean the default encoding should be changed
- if you change it, it would apply also to other Unicode/byte string
conversions, in places that doesn't have to do with the locale's
encoding. That's why it is a bad idea to change the default encoding.
Instead, there should be a convenient way to obtain the terminal's
encoding. Unfortunately, this is impossible to implement in the
general case.
Regards,
Martin
(*) this assumes that print goes to the terminal. If it goes to some
other stream, the definition of "will work" changes.
(**) there are still cases where it won't work. E.g. in a Windows
cmd.exe window, the OEM code page should be used, whereas the locale's
encoding would be the ANSI code page.