__author__ = 'Administrator' #coding = utf - 8 #python3默认都是Unicode格式的汉字 import sys s = u "中国" print ( type ( s )) # print ( type ( s . encode ( "utf-8" ))) s_utf_8 = s . encode ( "utf-8" ) print ( s_utf_8 ) #做成字节
#coding=utf-8#python3默认都是Unicode格式的汉字
import sys
s=u"中国"
print(type(s))
# print(type(s.encode("utf-8")))
s_utf_8=s.encode("utf-8")
print(s_utf_8)#做成字节了
print(sys.getdefaultencoding())、
__author__ = 'Administrator'
#coding=utf-8
# #python3默认都是Unicode格式的汉字
import sys
s="中国"
f=open("coding.txt","wb")
f.write(bytes(s,encoding="utf-8"))#encoding="utf-8"要写对了
f.close()
#在python3中str to bytes bytes(str)
#bytes to str bytes.decode("utf-8")
f=open("coding.txt","rb")
for i in f.readlines():
print(i.decode("utf-8"))