[Tutor] UTF-8 title() string method

Jon Crump jjcrump at myuw.net
Wed Jul 4 22:17:09 CEST 2007


Terry, thanks.

Sadly, I'm still missing something.

I've tried all the aliases in locale.py, most return
locale.Error: unsupported locale setting

one that doesn't is:

>>> locale.setlocale(locale.LC_ALL, ('fr_fr'))
'fr_fr'

but if I set it thus it returns:

Angoul?äMe, Angoumois.

I'm running python 2.5 on a Mac iBook G4 osX 10.4.10, and this encoding 
stuff is terra incognita for me


On Tue, 3 Jul 2007, Terry Carroll wrote:
> 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'))
> 'French_France.1252'
>>>> print s1.title()
> Angoul.me, Angoumois.
> 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