99

Python Unicode编码-Gorilla City-51CTO博客

 6 years ago
source link: http://blog.51cto.com/juispan/2066625
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
使用技巧事实上,只要遵守以下规则,可以规避90%由于Unicode字符串处理引起的bug,剩下的10%通过python的库和模块能够解决。程序中出现字符串时一定要加个前缀u。不要用str()函数,用unicode()代替。不要用过时的string模块——如果传给它的是非ASCII字符,它会把一切搞砸。不到必须时不要在你的程序里面解码unicode字符。只在你要写入文件或数据库或者网络时,才调用en

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK