使用纯&pythonic库将Unicode/UTF-8字符串转换为大写/小写字母

Vie*_*iet 11 python google-app-engine case-conversion

我使用谷歌应用程序引擎,不能使用任何C/C++扩展,只有纯和pythonic库来转换Unicode/UTF-8字符串到大/小写.str.lower()和string.lowercase()没有.

Ign*_*ams 24

str以UTF-8编码,unicode是两种不同的类型.不要使用string,在unicode对象上使用适当的方法:

>>> print u'?'.upper()
?
Run Code Online (Sandbox Code Playgroud)

使用之前解码strunicode:

>>> print '?'.decode('utf-8').upper()
?
Run Code Online (Sandbox Code Playgroud)

  • Viet:你可能想要对unicode字符进行URL编码,如果你把它们放在一个URL中(尽管你可能更容易将它们作为utf-8发布,假设你使用表单来提交它们). (3认同)