Python strings outside the 128 range

Michael Piotrowski mxp at dynalabs.de
Mon Jul 17 10:07:57 EDT 2006


On 2006-07-17 Piet van Oostrum <piet at cs.uu.nl> wrote:

>>>> That might be a good heuristic - but on my Mac no LANG is set. So I
>>>> should paraphrase my statement to "There is no reliable and
>>>> cross-platform way figuring out which encoding the console uses".
>
>>> If LANG is not set, it's equivalent to setting it to "C".  However,
>>> you shouldn't look directly at these variables (LANG and LC_*) but
>>> rather use the functions from the locale module, e.g.:
>
>>>   import locale
>>>   locale.setlocale(locale.LC_ALL, '') # use the current locale settings
>>>   encoding = locale.nl_langinfo(locale.CODESET)
>
> But if LANG isn't set (like on Mac OS X) this doesn't give you the proper
> encoding.

Well, yes, but it gives you something "safe" and you can advise the
user to set the locale.

> On my system I have added LANG to .profile.

That's certainly the right thing to do.

-- 
Michael Piotrowski, M.A.                               <mxp at dynalabs.de>
Public key at <http://www.dynalabs.de/mxp/pubkey.txt>



More information about the Python-list mailing list