1. 程式人生 > >字符的編碼和解碼

字符的編碼和解碼

utf-8 Coding decode encoding log gb2312 code logs unicode

字符的編碼和解碼

# Author:nadech
import sys
print(sys.getdefaultencoding())

#這裏的s的編碼方式還是unicode
s = "你好"

print(s.encode("gbk"))
print(s.encode("utf-8"))
print(s.encode("gb2312"))

#如果是utf8要轉化成gbk
s_utf8 = s.encode("utf-8")
print(s_utf8)
print(s_utf8.decode("utf-8").encode("gbk"))
print(s_utf8.decode("utf-8
").encode("gbk").decode("gbk"))

字符的編碼和解碼