我正在读取包含以下数据的文件,
char peer0_3[] = { /* Packet 647 */
0x02,0x00,0x04,0x11,0x01,0x06,0x1b,0x31,0x0a,0x32,0x30,0x39,0x2d,0x36,0x30 };
使用以下代码,以在python列表中获取此“ C”文本
f=open(thisFile,'r')
contents=f.read()
tcontents=re.sub('\/\*.*\*\/','',contents).replace('\n','').strip() #suppress the comments
xcontents = re.findall("{(.+?)};",tcontents,re.S) #find the arrays
frames=[]
for item in xcontents:
splitData =item.split(',')
buff=bytes()
for item in splitData:
packed = struct.pack("B",int(item,0) )
buff+=packed
frames.append(buff)
这很好,但是我想知道是否没有更聪明,更紧凑的方法? 如果有人想调查这个....