如何在文件中存储256作为整数?

时间:2017-04-04 09:57:33

标签: python

我正在学习LZW数据压缩,我想存储数字>文件中有255个。数字不应存储为字符串,否则压缩将无效。但是,二进制文件只存储数字< = 255.如何存储大于255的数字,这样当我读回它们时,我会得到原始整数?

lst = [256]

writefile = open("C:/Users/Dhruv/Desktop/write.bin", "wb")

buffer = bytes(lst)

print(buffer)

writefile.write(buffer)
writefile.close()
readfile = open("C:/Users/Dhruv/Desktop/write.bin", "rb")
bin = readfile.read(1)

print(ord(bin))

readfile.close()

0 个答案:

没有答案