Convert Unicode/UTF-8 string to lower/upper case u

2020-06-12 04:16发布

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.

1条回答
我想做一个坏孩纸
2楼-- · 2020-06-12 04:19

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()
Ĉ
查看更多
登录 后发表回答