我在使用python讀取幾十萬行的文件中的數(shù)據(jù),并構(gòu)造字典,列表等數(shù)據(jù)結(jié)構(gòu)時,再訪問字典,列表時,一般都會出現(xiàn)內(nèi)存不夠的問題,然后只能循環(huán)讀取幾百行或者一定數(shù)量的行數(shù)來循環(huán)操作。
keyword_list=[line.strip() for line in open("keywords.txt",'r')]#f1=open("part_wiki_vec.txt",'r')f1=open("wiki_vectors.txt")f2=open("result.txt",'w')i=0content=f1.readlines()while i<1150: for line in content[300*i:300*(i+1)]: line=line.strip().split(' ') if line[0] in keyword_list: wordvec=' '.join(line) print wordvec f2.write(wordvec) #print line i+=1我是這樣讀取的
應(yīng)該還有很多好的方法,比如多線程等等。
做此記錄只為了學(xué)習(xí)
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,謝謝大家對VEVB武林網(wǎng)的支持。
新聞熱點
疑難解答
圖片精選