我覺得我雖然不是你所要完成
symbolList=[]
for line in open('datafile.txt','r'):
if '.o' in line:
tempname=line.split()[-1][0:-2]
pass
if 'FUNC' not in line:
pass
else:
symbolList.append((tempname,line.split('|')[0]))
我已經從其他崗位瞭解到它是便宜什麼完全清楚,這可能花費比使用正則表達式的少並且在第一次閱讀文件時更好地包裝所有數據。因此,如果你想包了整個數據文件在一通,然後你可以做以下代替
fullDict={}
for line in open('datafile.txt','r'):
if '.o' in line:
tempname=line.split()[-1][0:-2]
if '|' not in line:
pass
else:
tempDict={}
dataList=[dataItem.strip() for dataItem in line.strip().split('|')]
name=dataList[0].strip()
tempDict['Value']=dataList[1]
tempDict['Class']=dataList[2]
tempDict['Type']=dataList[3]
tempDict['Size']=dataList[4]
tempDict['Line']=dataList[5]
tempDict['Section']=dataList[6]
tempDict['o.name']=tempname
fullDict[name]=tempDict
tempDict={}
然後,如果你想要的函數功能類型,你可以使用如下:
funcDict={}
for record in fullDict:
if fullDict[record]['Type']=='FUNC':
funcDict[record]=fullDict[record]
對不起,我是如此癡迷,但我試圖更好地處理創建列表解析的問題,並且我決定這是值得的拍攝
如果給出文本逐字逐句,您將得到一個IndexError(索引超出範圍) 。 – hbw 2009-05-04 06:09:50
哎呀,好點。我認爲新版本不會有,因爲它只在有|時纔會分裂字符在行中。 – JasonSmith 2009-05-04 06:14:40
+1用於提取.o名稱 – 2009-05-05 01:26:14