原因:txt包含BOM字符
处理办法有三种。
一、可通过NotePad 将Txt 文档修改为UTF-8 Without BOM
二、python脚本,读取txt文件时,encoding="utf-8-sig"
file_path = "E:/国际化/"
with open(file_path + "English.txt", encoding="utf-8-sig") as obj_file:
english_content = obj_file.read()
三、将BOM头去掉
file_path = "E:/国际化/"
with open(file_path + "English.txt", encoding="utf-8") as obj_file:
english_content = obj_file.read()
# print(english_content)
if english_content.startswith(u'/ufeff'):
english_content = dict_english.encode('utf8')[3:].decode('utf8')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)