该文件不适合内存。它超过100GB,我想按行号访问特定的行。我不想在我到达之前一行一行地进行计数。 我已阅读http://docstore.mik.ua/orelly/perl/cookbook/ch08_09.htm 当我使用以下方法建立了一个指数,该行工作的回报达到一定点。一旦行号非常大,返回的行是相同的。当我到文件中的特定行时,返回同一行。它似乎适用于行号1至350000(大约); # us
我想读一个文本文件,并返回不以#开头的行。在Python中,我可以很容易地使用列表理解列表 with open('file.txt') as f:
lines = [l.strip('\n') for l in f.readlines() if not re.search(r"^#", l)]
我想通过Groovy完成同样的事情。到目前为止,我有下面的代码,非常感谢任何帮助。 lin
我有一个数据列的文本文件,我需要把这些列变成单个列表或数组。 这是我迄今为止 f = open('data.txt', 'r')
temp = []
for row in f.readlines():
Data = row.split()
temp.append(float(Data[0]))
当我运行此我得到IndexError: list index out of
我在读取特定行时遇到问题。这与这里回答的问题类似: python - Read file from and to specific lines of text 区别,我没有固定的结束标记。让我给个例子: --------------------------------
\n
***** SOMETHING ***** # i use this as my start
\n
-------
我无法通过python读取特定行。什么我的工作是这样的: lines of data not needed
lines of data not needed
lines of data not needed
--------------------------------------
***** REPORT 1 *****
--------------------------