約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でエラーが発生しないことです。そのため、問題が何であるかを理解するのに苦労しています。