我尝试在两个文件之间进行链式比较,并在指定的时间间隔内打印/写出结果。在
这就是我目前所拥有的。在
test1文件:
A0AUZ9,7,17 #just this one line
测试2文件:
^{pr2}$剧本本身:
results = []
with open('test1', 'r') as disorder:
for lines in disorder:
cells = lines.strip().split(',')
with open('test2', 'r') as helpy:
for lines in helpy:
blocks = lines.strip().split(',')
if blocks[0] != cells[0]:
continue
elif cells[1] <= blocks[2] and blocks[3] <= cells[2]:
results.append(blocks)
with open('test3','wt') as outfile:
for i in results:
outfile.write("%s\n" % i)
我的首选输出是只包含test3中的行,即:
在第一列中有匹配的ID
第3列和第4列中的两个数值介于test1文件中给定的值之间
我没有输出,也不知道哪里出了问题。在
它不能像预期的那样工作的原因之一是你在比较字符串而不是数字。在
然而,也许有更好的方法来做你想做的事情。假设第一个文件足够小,可以放入内存:
相关问题 更多 >
编程相关推荐