我正在做一个虚拟内存模拟器,但我遇到了问题。我需要从 k(4) 个文件中读取 n (8) 行,例如:我读取文件 1 - 文件 2 - 文件 3 - 文件 4 的前 8 行,然后我再次从每个文件中读取第 9 - 17 行, 直到每个文件用完行。
我对文件的输入没有问题,并且已经完成了这段代码。
def rr_process(quantum, file, fline):
global rr_list #List to save the reading lines
condition = file_len(file) #Return the total lines of passed file
with open(file) as fp:
line = fp.readlines() #Save all the lines of the file in a list
for i in range(fline,fline+quantum): #for i in range(NewStartLine, NewStartLie + n_lines)
if i <= condition-1:
sline = line[i].rstrip()#Remove /n from lines
rr_list.append(sline) #append the n_lines to the list
else:
break
operation = concat_count//(n_proc*quantum) #total_lines//(k_files*n_lines)
for i in range(0,operation):
for fname in process: #Open each file (4)
rr_process(quantum,fname,fline) #Calls the read lines function
fline = fline + quantum + 1 #New start line number 0-9-17...
我根本没有成功,我需要读取 50k 行但我的程序只读取 44446。代码中的错误是什么?或者有什么更好的方法来处理这个?多谢你们!