python一些編碼的轉換格式問題
python經常有一些編碼格式的問題西面有幾種轉碼的方式:
unicodestring = u"Hello world"
# 將Unicode轉化為普通Python字串:"encode"
utf8string = unicodestring.encode("utf-8")
asciistring = unicodestring.encode("ascii")
isostring = unicodestring.encode("ISO-8859-1")
utf16string = unicodestring.encode("utf-16")
# 將普通
Python字串轉化為Unicode:"decode"plainstring1 = unicode(utf8string, "utf-8")
plainstring2 = unicode(asciistring, "ascii")
plainstring3 = unicode(isostring, "ISO-8859-1")
plainstring4 = unicode(utf16string, "utf-16")
assert plainstring1 == plainstring2 == plainstring3 == plainstring4