On Apr 19, 1:53 am, Ben Finney wrote:
> Damon Wischik writes:
>> Why does it matter what locales my OS supports, when all I want is
>> to set the encoding to be used for the output
>
> Because the Python 'locale' module is all about using the OS's
> (actually, the underlying C library's) locale support.
>
> The locale you request with 'locale.setlocale' needs to be supported
> by the locale database, which is independent of any specific
> application, be it Python, Emacs, or otherwise.

Let me try to ask a better question. It seems that the logical choice
of locale (en_GB.utf8) is not supported by my operating system.
Nonetheless, I want Python to output in utf-8, because I know for
certain that the terminal I am using (Emacs 22.2.1 with python-mode)
will display utf-8 correctly. It therefore seems that I cannot use the
locale mechanism to indicate to Python the encoding I want for
sys.stdout. What other mechanisms are there for me to indicate what I
want to Python?

Another poster pointed me to
>> sys.stdout = codecs.getwriter("UTF-8")(sys.stdout)
and this works great. All I want now is some reassurance that this is
the most appropriate way for me to achieve what I want (e.g. least
likely to break with future versions of Python, most in keeping with
the design of Python, easiest for me to maintain, etc.).

Damon.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to