python UTF-8转GBK字符编码问题(BOM)
文章目录
不知道为什么,明明是utf-8偏偏会遇到bom的问题,那就奥里给
\u2022
def u8togbk(self, infn, outfn):
with open(infn, 'r', encoding='utf-8') as f:
reader = csv.reader(f)
results = list(reader)
results[0][0] = results[0][0].replace('\ufeff', '').replace('\xa0', '').replace('\u3000', '').replace('\u2022', '')
with open(outfn, 'w', encoding='gbk', newline='') as f:
writer = csv.writer(f)
for result in results:
writer.writerow(result)

评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论