python将txt转16进制
直接上代码
import time
print("begin")
#读取的txt文件
infile = open("xxx.txt","r");
#
outfile = open("xxx.hex","wb");
#开始读文件
a = infile.read(1);
_combine = "";
i=0;
while a != '\n':
if ' ' == a:
a = infile.read(1);
continue;
else:
_combine = _combine + a;
i = i+1;
if 2 == i :
i = 0;
#转化为16进制
outfile.write(bytes.fromhex(_combine));
_combine = "";
a = infile.read(1);
infile.close();
outfile.close();
print("getit")