У меня было много проблем с этим, и другие вопросы, похоже, не то, что я ищу. Таким образом, в основном, у меня есть список байт получил отЗапись двоичных данных в файл в 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