【发布时间】:2015-12-11 13:52:21
【问题描述】:
我必须在一个巨大的文本文件中获取特定的行。直到现在我尝试如下。我的目标是为特定迭代提取列,这里每 500 行。但是通过继续“readlines”,有时我会因为文件的大小(直到 4Gb)而崩溃。 所以我想找到另一种方法来避免问题......
with open('/test.txt') as f:
text = f.readlines()
A = ""
for i in text[3000:3500]:
A+=i
B=A.splitlines()
listed = []
for i in range(len(B)):
C=B[i][3:47].split(" ")
while True:
try:
C.remove("")
except ValueError:
break
listed.append(C)
import numpy as np
import matplotlib.pyplot as plt
#print listed
x = np.array(listed, dtype=float)
y = x.astype(np.float)
plt.plot(y[:,1]);plt.ylim(0,5);plt.show()
这篇文章跟随前question。
【问题讨论】: