「それほどでもない」大きなファイル(〜2.2GB)を読んで処理しようとしています...
graph = defaultdict(dict)
error = open("error.txt","w")
print "Reading file"
with open("final_edge_list.txt","r") as f:
for line in f:
try:
line = line.rstrip(os.linesep)
tokens = line.split("\t")
if len(tokens)==3:
src = long(tokens[0])
destination = long(tokens[1])
weight = float(tokens[2])
#tup1 = (destination,weight)
#tup2 = (src,weight)
graph[src][destination] = weight
graph[destination][src] = weight
else:
print "error ", line
error.write(line+"\n")
except Exception, e:
string = str(Exception) + " " + str(e) +"==> "+ line +"\n"
error.write(string)
continue
私は何か間違ったことをしていますか??
コードがファイルを読み込んでから 1 時間ほど経ちました (まだ読み込んでいます..)
そして、メモリ使用量の追跡はすでに20GBです..なぜそんなに時間とメモリがかかるのですか??