Locale settings

Bob van der Poel bvdpoel at kootenay.com
Tue Apr 22 19:50:04 EDT 2003


"Martin v. Löwis" <martin at v.loewis.de> wrote in message news:<b81k5m$822$06$1 at news.t-online.com>...
> Bob van der Poel wrote:
> 
> > Now, for the most part this works. However, one user of my program has 
> > just upgraded to Linux Mandrake 9.1 and (I think) he has set his 
> > language to "de". In any event, the getdefaultlocal() seems to return 
> > 'de' which isn't a valid python encoding (??) and the above code then 
> > converts to his 'ascii'.
> 
> Using getdefaultlocale() is broken, and cannot be fixed. On Unix, use
> 
> locale.nl_langinfo(locale.CODESET)
> 
> instead; if supported, this will tell you the user's preferred encoding.
> Be aware that
> a) neither nl_langinfo nor CODESET may be supported by the system,
> b) they may return a codeset for which a Python codec is not available,
> c) you may have to invoke setlocale(locale.LC_CTYPE, "") before
>     nl_langinfo returns a reasonable response (e.g. on Solaris)
> 
> Python 2.3 has a function locale.getpreferredencoding which does all
> that. I recommend you copy its source code into your application, and
> use that instead.

Thanks for the reply. I guess I'll be downloading 2.3 earlier than I'd
planned on. I really do like to get past the beta versions :) But, if
I can snarf the local stuff out of it and have it work with my 2.2
code, that'd be fine. Guess I  can use the included version for awhile
and then, once 2.3 become common, just tell users to use that python
version.

The funny think about all this is that my user didn't have any
problems when he was using Mandrake Linux 9.0. Just the upgrade to 9.1
which caused the problem. Which is why I was thinking that he'd not
set the locale stuff up properly at his end.

Thanks.




More information about the Python-list mailing list