【发布时间】:2019-09-13 23:57:32
【问题描述】:
我正在尝试将两个 LARGE 输入文件合并为 1 个输出,同时进行排序。
## Above I counted the number of lines in each table
print("Processing Table Lines: table 1 has " + str(count1) + " and table 2 has " + str(count2) )
newLine, compare, line1, line2 = [], 0, [], []
while count1 + count2 > 0:
if count1 > 0 and compare <= 0: count1, line1 = count1 - 1, ifh1.readline().rstrip().split('\t')
else: line1 = []
if count2 > 0 and compare >= 0: count2, line2 = count2 - 1, ifh2.readline().rstrip().split('\t')
else: line2 = []
compare = compareTableLines( line1, line2 )
newLine = mergeLines( line1, line2, compare, tIndexes )
ofh.write('\t'.join( newLine + '\n'))
我期望发生的是,当将行写入输出时,如果可用,我会拉出我曾经读入的文件中的下一行。我还希望一旦两个文件都为空,循环就会中断。
但是我不断收到此错误: ValueError:混合迭代和读取方法会丢失数据
我只是不知道如何绕过它。任何一个文件都太大而无法保存在内存中,所以我想边读边读。
【问题讨论】:
-
两个输入文件是否排序?你能给我们看一些例子吗?
compareTableLines()是做什么的?