【发布时间】:2013-11-21 19:34:45
【问题描述】:
我在这方面遇到了很多麻烦,其他问题似乎不是我要找的。所以基本上我有一个从
获得的字节列表bytes = struct.pack('I',4)
bList = list(bytes)
# bList ends up being [0,0,0,4]
# Perform some operation that switches position of bytes in list, etc
所以现在我想把它写到一个文件中
f = open('/path/to/file','wb')
for i in range(0,len(bList)):
f.write(bList[i])
但我不断收到错误
TypeError: 'int' does not support the buffer interface
我也试过写:
bytes(bList[i]) # Seems to write the incorrect number.
str(bList[i]).encode() # Seems to just write the string value instead of byte
【问题讨论】:
标签: python-3.x bytearray binaryfiles