Convert on uppercase unaccentent unicode character

Duncan Booth duncan.booth at invalid.invalid
Wed Oct 3 15:37:25 EDT 2007


timaranz at gmail.com wrote:

> On Oct 4, 7:35 am, JBJ <Jean-Bernard.jacquet-at-tele-deux-
> point... at invalid.org> wrote:
>> Hi,
>> I'am very newbie in Python.
>> For the moment I'am trying to convert an unicode character to his
>> uppercase unaccented character.
>> By example with locale fr_FR:
>> a,A,à,À should return A
>> o,O,ô,Ô should return O
>> ½,¼ should return ¼
>> i,I,î,Î should return I
>>
>> Have you some suggestions ?
>>
>> Thank.
> 
> Unicode strings have an upper() method - try that.  I'm think it
> should work properly with your locale - it doesn't give the expected
> result for me with an english locale.
> 
No, that will uppercase the string, but it doesn't (and shouldn't) strip 
the accents:

>>> s = u'''By example with locale fr_FR:
a,A,à,À should return A
o,O,ô,Ô should return O
½,¼ should return ¼
i,I,î,Î should return I'''
>>> print s.upper()
BY EXAMPLE WITH LOCALE FR_FR:
A,A,À,À SHOULD RETURN A
O,O,Ô,Ô SHOULD RETURN O
½,¼ SHOULD RETURN ¼
I,I,Î,Î SHOULD RETURN I
>>> 

I guess maybe my newreader corrupted the third line. It probably corrupts 
all the others when I send this.



More information about the Python-list mailing list