我有一个大约 10,000 行的文本文件。
典型的行如下所示:
'1 2/1/2011 9:30,ZQZ,200.02,B,500'
如果我运行#1,我可以遍历整个文件,并i
计算文件中的总行数。但是,如果我创建一个字典,在遍历文件时记录每一行中的数据(如 #2 所示),我将完成大约一半。我无法弄清楚为什么会这样。10,000 行数据是否可能太大而无法包含在字典中?我怎样才能确定这一点?#1 TheFile = open(file_name) TheFile.next()
i = 0
for l in TheFile:
i += 1
print i
#2
TheFile = open(file_name)
TheFile.next()
thedata = {}
i = 0
for l in TheFile:
i += 1
print i
this_line = TheFile.next()
the_info = this_line.split(',')
the_ticker = the_info[1]
#print type(the_info[1])
#print this_line
if the_ticker not in thedata.keys():
thedata[the_ticker] = {}
thedata[the_ticker]['trade'+ str(len(thedata[the_ticker]) + 1)] =
{'the_trade_number':len(thedata[the_ticker]),
'theTime':the_info[0],
'thePrice':float(the_info[2]),
'theTransaction':the_info[3],
'theQuantity':int(the_info[4])}
问题是#2没有给我任何错误,这就是为什么我无法弄清楚问题所在