import os files = [] outF = open('allPreds_sep24.txt', 'w') predDir = '/home/jluttrell/contactPred/bmcBioinformaticsRedo_july2018/meanDecreaseAccuracy/sda/sep24/unbalanced/finalEnsemble/preds/training/all/' predLen = 371344 #the number of lines in each predfile. needs to be the same in each for file in sorted(os.listdir(predDir)): if not file.endswith('.pred'): continue files.append(open(predDir + file, 'r')) lc = 0 while lc < predLen: line = "" for f in files: tl = f.readline().rstrip() items = tl.split() if 'e' in items[0]: items[0] = '0.0' if 'e' in items[1]: items[1] = '0.0' line = line + items[0] + ' ' + items[1] + ' ' outF.write(line + '\n') lc += 1