python3 读入字符串类型,输出16进制文件

输入如下,只有1行,考虑到做结束,需要在末尾加换行。

AA 44 12 1C 8C 00 00 02 8C 08 00 00 61 A0 02 08 38 

输出直接为16进制,考虑到空格,做了计数器来跳空格。
python3 读入字符串类型,输出16进制文件

import time
print("hello world")


#infile = open("201904251.log","r");
infile = open("1.log","r");
outfile = open("out.log","wb");
_log = open("log.log","w");
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;
            #print(_combine);
            #_log.write(" "+_combine);
            outfile.write(bytes.fromhex(_combine));
            _combine = "";
    a = infile.read(1);

infile.close();
outfile.close();
_log.close();