测试utf-8 & gbk & unicode 编码解码

时间:2023-01-05 10:23:51
# coding:UTF-8
#测试编码
#str--------->unicode--------->str
#---decode------------encode-----
#str=gbk/utf-8

import platform

print "###########################"
print "python version=",
print platform.python_version()
print "###########################"

#u表示是unicode的
input=u"娱乐"

print "unicode=",
print repr(input)
    
out_utf8=input.encode('utf-8')
print "utf-8=",
print out_utf8             ,
print repr(out_utf8)

out_gbk=input.encode('gbk')
print "gbk=",
print out_gbk            ,
print repr(out_gbk)

#---------------------------
#utf8--------------->gbk
#inUTF8="娱乐"
#outGBK=inUTF8.decode('utf-8').encode('gbk')
#print repr(outGBK)