本文介绍了python 2.7小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在 Python 2.7 中使用 .lower() 时,字符串不会转换为字母 ŠČŽ 的小写.我从字典中读取数据.
When I use .lower() in Python 2.7, string is not converted to lowercase for letters ŠČŽ. I read data from dictionary.
我尝试使用 str(tt["code"]).lower(), tt["code"].lower().
有什么建议吗?
推荐答案使用 unicode 字符串:
Use unicode strings:
drostie@signy:~$ python Python 2.7.2+ (default, Oct 4 2011, 20:06:09) [GCC 4.6.1] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> print "ŠČŽ" ŠČŽ >>> print "ŠČŽ".lower() ŠČŽ >>> print u"ŠČŽ".lower() ščž看到那个小u了吗?这意味着它是作为 unicode 对象而不是 str 对象创建的.
See that little u? That means that it's created as a unicode object rather than a str object.
更多推荐
python 2.7小写
发布评论