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

感情迁移 提交于 2019-12-04 17:48:25

问题


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:


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()
Ĉ


来源:https://stackoverflow.com/questions/2145826/convert-unicode-utf-8-string-to-lower-upper-case-using-pure-pythonic-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!