История изменений
Исправление vvn_black, (текущая версия) :
import struct
string = 'Hello'
num = 900
with open('test.bin', 'wb') as f:
f.write(struct.pack(f'>i{len(string)}s', num, string.encode()))
$ hexdump -C test.bin
00000000 00 00 03 84 48 65 6c 6c 6f |....Hello|
00000009
Исходная версия vvn_black, :
import struct
string = 'Hello'
num = 900
with open('test.bin', 'wb') as f:
f.write(struct.pack(f'>i{len(string)}s', num, string.encode()))