[英]How to remove BOM characters from a string in Python 3.9.6?
I have a bytestring that I'm supposed to send to a zipfile using Pyhton's built in zipfile.writestr
but in the beginning of each of the files there's a small (14-15) chars BOM character string and one big one at the end of the entire file, the final csv file looks like this(example):我有一个字节串,我应该使用 Pyhton 内置的
zipfile.writestr
将它发送到一个zipfile ,但是在每个文件的开头都有一个小(14-15)个字符的 BOM 字符串和一个大的在结尾处整个文件,最终的csv文件如下所示(示例):
filename1
(BOM characters)Column1, Column2, Column3
data1, data2, data3
data4, data5, data6
filename2
(BOM characters)Column1, Column2, Column3
data1, data2, data3
(BOM characters)
I've tried using .decode("utf-8-sig")
but it showed no difference.我试过使用
.decode("utf-8-sig")
但它没有显示出区别。
So it turns out I was saving the file zip file as csv and that was the cause of the issue.所以事实证明我将文件zip文件保存为csv ,这就是问题的原因。 Now that I saved it as zip everything works fine.
现在我将它保存为zip一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.