dumbass locale question
Michael Hudson
mwh21 at cam.ac.uk
Thu Feb 17 12:31:04 EST 2000
Skip Montanaro <skip at mojam.com> writes:
> I run a web site here in the US, but I get input from all over. If I ask
> for
>
> "c".upper()
>
> I get the appropriate response: "C". However, if I ask for "é".upper(), I
> don't get "É", I just get "é".
>
> I don't have the luxury of assuming that my users come from one locale or
> another. I can assume for the most part that they are entering letters that
> come pretty much from the Latin-1 character set. To get "é".upper() to work
> can I play some tom-foolery with the locale or must I craft my own upper()
> and lower() functions?
Seems to me that setting LC_CTYPE to just about anything other than
`C' does the trick:
[mwh21 at atrus speedtest]$ LC_ALL=en python # my LC_ALL is usually en_GB
Python 1.5.2+ (#13, Jan 14 2000, 09:26:45) [GCC 2.95.2 19991024 (release)] on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> print 'é'.upper()
é
>>> import locale
>>> print 'é'.upper()
é
>>> locale.setlocale(locale.LC_CTYPE )
'C'
>>> print 'é'.upper()
é
>>> locale.setlocale(locale.LC_CTYPE,"en_US" )
'en_US'
>>> print 'é'.upper()
É
>>> locale.setlocale(locale.LC_CTYPE,"C" )
'C'
>>> print 'é'.upper()
é
I don't really understand this either, but I hope this is of some use.
Probably depends on you libc, too.
Cheers,
M.
More information about the Python-list
mailing list