Some information about locale (was Re: [Python-Dev] repr vs. str and locales again)

Guido van Rossum guido@python.org
Mon, 22 May 2000 09:54:35 -0700


> pf@pefunbk> python 
> Python 1.5.2 (#1, Jul 23 1999, 06:38:16)  [GCC egcs-2.91.66 19990314/Linux (egcs- on linux2
> Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
> >>> import string
> >>> print string.upper("")
> 
> >>> 

This threw me off too.  However try this:

python -c 'print "".upper()'

It will print "".  A mystery?  No, the GNU readline library calls
setlocale().  It is wrong, but I can't help it.  But it only affects
interactive use of Python.

> In recent Linux distributions almost every Linux C-program seems to 
> contain this obligatory 'setlocale(LC_ALL, "");' line, so it's easy 
> to forget about it.  However the core Python interpreter does not.
> it seems the Linux C-Library is not fully ANSI compliant in this case.
> It seems to honour the setting of $LANG regardless whether a program
> calls 'setlocale' or not.

No, the explanation is in GNU readline.

Compile this little program and see for yourself:

#include <ctype.h>
#include <stdio.h>

main()
{
	printf("toupper(%c) = %c\n", '', toupper(''));
}

--Guido van Rossum (home page: http://www.python.org/~guido/)