附上代码,python 2.7
# _*_ coding:utf-8 _*_
import xlwt
import sys
wb=xlwt.Workbook()
ws=wb.add_sheet('shuju')
f=open(r'D:\car\carlist.txt')
for j in range(1,4):
x=f.readline()
y=x.split()
print y
for i in range(0,5):
ws.write(j,i,y[i])
ws.write(10,10,"test")
stdout=sys.stdout
reload(sys)
sys.stdout=stdout
sys.setdefaultencoding('UTF-8')
wb.save('shuju1.xls')
我保存的shuju1.xls没有找到,也搜索不到。
ringa_lee2017-04-17 17:55:50
I just tried it again and found that the problem was solved after deleting # coding:utf-8 __. When I first looked at the learning materials, I only knew that the encoding format should be set at the beginning. I didn’t care why the encoding format was set. I need to study and study the content of this encoding.