往文件中写入中文,再从文件中读出,范例1:
#coding:utf-
with open('data.log','w') as f:
a=u'中文'
b = a.encode('gbk')
f.write(b) with open('data.log','r') as f:
l1= f.readlines()
print l1[]
写入中文,范例2:
#-*- coding:gbk-*-
file='test.txt'
a=u'中文'
b=a.encode('utf')
f=open(file,"w")
f.write(b)
f.close()
print "successful"