1
我一直有這個問題很多,其他問題似乎並不是我正在尋找的。所以基本上我有將二進制數據寫入python3中的文件
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