将十六进制数据放在data.txt里,前提是十六进制符合期望文件格式
例如该十六进制数据为
504B03040A0001080000739C8C4B7B36E495200000001400000004000000666C616781CD460EB62015168D9E64B06FC1712365FDE5F987916DD8A52416E83FDE98FB504B01023F000A0001080000739C8C4B7B36E4952000000014000000040024000000000000002000000000000000666C61670A00200000000000010018000DB39B543D73D301A1ED91543D73D301F99066543D73D301504B0506000000000100010056000000420000000000
504B0304 zip的头文件格式
import struct a = open("data.txt","r")#十六进制数据文件 lines = a.read() res = [lines[i:i+2] for i in range(0,len(lines),2)] with open("data.zip","wb") as f: for i in res: s = struct.pack('B',int(i,16)) f.write(s)
得到data.zip
标签:十六进制,zip,文件,lines,文件格式,txt,data From: https://www.cnblogs.com/willingyut/p/17659250.html