1. 程式人生 > >python 2.x編解碼

python 2.x編解碼

文件 utf8 獲取 asc sys sci enc port imp

#-- coding:utf-8 -- #文件指定為utf-8編碼 Python 2.x的程序默認編碼為ascii
import sys
print(sys.getdefaultencoding()) #獲取程序默認編碼
s = u"你好"
#u代表unicode
print(s)
#s_to_unicode = s.decode("utf-8")
#print(s_to_unicode)
s_to_gbk = s.encode("gbk")
print(s_to_gbk)
#print("你好")
gbk_to_utf8 = s_to_gbk.decode("gbk").encode("utf8")
print(gbk_to_utf8)

python 2.x編解碼