我有一个巨大的文本文件,类似于下面链接中的表格。每个xxx框有不同的行数,但列数相同:
这是指向图的链接
我无法编写适用于整个文本文件的通用python代码。你能帮我一下吗?
我试过这段代码,但我发现了错误:
发布于 2016-04-13 17:32:11
我相信你要找的东西的总体布局是:
with open('file','r') as file:
groups = [] # Will contain the final data
current_group = [] # Temporary
line = file.readline()
while line != "":
if line == "XXXX":
# Store the current group and start a new one
groups.append(current_group)
current_group = []
else:
# Add the number to the current group
current_group.append(int(line.split()[2]))
line = file.readline()https://stackoverflow.com/questions/36604194
复制相似问题