[Tutor] UTF-8 title() string method

Terry Carroll carroll at tjc.com
Wed Jul 4 03:30:13 CEST 2007

On Tue, 3 Jul 2007, Jon Crump wrote:

> but where there are diacritics involved, title() gives me:
> AngoulMe, Angoumois.
> Can anyone give the clueless a clue on how to manage such unicode strings 
> more effectively?

I think setting the locale is the trick:

>>> s1 = open("text.txt").readline()
>>> print s1
ANGOUL.ME, Angoumois.
>>> print s1.title()
Angoul.Me, Angoumois.
>>> import locale
>>> locale.setlocale(locale.LC_ALL,('french'))
>>> print s1.title()
Angoul.me, Angoumois.

(sorry about the '.' for the characters that my term program won't accept)

You might have to hunt around and experiment for the right locale that 
will work in all your cases.

More information about the Tutor mailing list