Python3 將16進制數據寫入二進制文件

import struct
li=[0x50,0x4b,0x3,0x4] #待寫入的數據
with open("testfile","wb") as fp:
    for x in array:
        s = struct.pack('B',x)#轉換爲字節流字符串,B代表unsigned char
        fp.write(s)
fp.close()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章