python读取中文报错

# -*-coding:utf-8-*-
f = open("D://test.txt","r",encoding="utf-8")
lines = f.readlines()
fout=open('D://kid.txt','w',encoding='utf-8')
for line in lines:
    print(line)
    fout.write(line)
    fout.write('\n')#这是换行
fout.close()


  1. 打开的时候设置编码

    f = open(“D://test.txt”,“r”,encoding=“utf-8”)

  2. 将txt 文件也设置编码

评论