赞
踩
纯英文excel,excel本身并未乱码,使用xlrd库读出后字符串依然正常,在写入txt后出现乱码:
def make_txt(file, data_list):
os.remove(file)
with open(file,"a", encoding='utf-8') as f:
for i in range(len(data_list)):
# print(data_list[i][1])
try:
if data_list[i][0] != " ":
f.write(str(data_list[i][0]) + " " + str(data_list[i][1]) + "\n")
except UnicodeEncodeError:
pass
print("make txt sucessfully!")
在写入txt的时候,指定utf-8
编码格式:
with open(file,"a", encoding='utf-8') as f:
问题解决!
txt乱码情况解决。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。