Python strings outside the 128 range

Michael Piotrowski mxp at dynalabs.de
Mon Jul 17 06:30:48 EDT 2006


On 2006-07-14 "Diez B. Roggisch" <deets at nospam.web.de> wrote:

> Sybren Stuvel schrieb:
>> Diez B. Roggisch enlightened us with:
>>> Of course not. AFAIK there is no way figuring out which encoding the
>>> target console supports. The best you can do is to offer an option
>>> that allwos selection of the output encoding.
>> 
>> You can use the LANG environment variable on many systems. On mine,
>> it's set to en_GB.UTF-8, which causes a lot of software to
>> automatically choose the right encoding.
>
> 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)

-- 
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