泡菜转储方法添加Wierd二进制数据
每个人!
我在文件中使用pickle.dump()编写一些二进制数据,然后读取以下代码的文件。
import numpy as np
import pickle
save_file = open('test.rdb','wb')
save_data = np.array([1, 2, 3])
pickle.dump(np.ndarray.tobytes(save_data),save_file)
save_data = np.array([1.0, 2.0, 3.0])
pickle.dump(np.ndarray.tobytes(save_data),save_file)
save_file.close()
read_file = open('test.rdb','rb')
data = read_file.read()
print(data)
当我使用十六进制编辑器打开文件时,有一些我没有编写的数据。 (下图中的红色框)
这些是什么?我该如何删除它们?
everyone!
I write some binary data using pickle.dump() in a file, and read the file as below code.
import numpy as np
import pickle
save_file = open('test.rdb','wb')
save_data = np.array([1, 2, 3])
pickle.dump(np.ndarray.tobytes(save_data),save_file)
save_data = np.array([1.0, 2.0, 3.0])
pickle.dump(np.ndarray.tobytes(save_data),save_file)
save_file.close()
read_file = open('test.rdb','rb')
data = read_file.read()
print(data)
When I open the file using hex editor, there are some data that I didn't write.
(Red box in the picture below)
What are those? and how can I remove them?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议不要使用Pickle来转储文件,而请使用Python默认打开函数在WB中打开文件,然后转储文件。倾倒时,它不会添加任何额外的二进制字节。
I suggest instead of using pickle to dump file, use python default open function to open file in wb and then dump the file. It will not add any extra binary bytes when dumping.