Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Unicode/UTF-8 string to lower/upper case using pure & pythonic library

I use Google App Engine and cannot use any C/C++ extension, just pure & pythonic library to do conversion of Unicode/UTF-8 strings to lower/upper case. str.lower() and string.lowercase() don't.

like image 553
Viet Avatar asked Jan 27 '10 09:01

Viet


1 Answers

str encoded in UTF-8 and unicode are two different types. Don't use string, use the appropriate method on the unicode object:

>>> print u'ĉ'.upper()
Ĉ

Decode str to unicode before using:

>>> print 'ĉ'.decode('utf-8').upper()
Ĉ
like image 95
Ignacio Vazquez-Abrams Avatar answered Oct 03 '22 20:10

Ignacio Vazquez-Abrams