python Unicode 编码解码

 1 #将Unicode转换成普通的Python字符串:"编码(encode)"
2 unicodestring = u"Hello world"
3 utf8string = unicodestring.encode("utf-8")
4 asciistring = unicodestring.encode("ascii")
5 isostring = unicodestring.encode("ISO-8859-1")
6 utf16string = unicodestring.encode("utf-16")
7
8
9 #将普通的Python字符串转换成Unicode: "解码(decode)"
10 plainstring1 = unicode(utf8string, "utf-8")
11 plainstring2 = unicode(asciistring, "ascii")
12 plainstring3 = unicode(isostring, "ISO-8859-1")
13 plainstring4 = unicode(utf16string, "utf-16")
14
15 assert plainstring1==plainstring2==plainstring3==plainstring4
上一篇:issubclass判断前面是不是后面的子类


下一篇:Query意图分析:记一次完整的机器学习过程(scikit learn library学习笔记)