from glob import glob import os, codecs files = [y for x in os.walk("tests/") for y in glob(os.path.join(x[0], '*.in'))] largeinput = "" for fl in files: f = codecs.open(fl, "rb", "utf-8") lines = f.readlines() f.close() for line in lines: line = line.strip() if line: linearray = line.split("\t") if len(linearray) >= 2: largeinput = largeinput + line + "\n" largeinput = '\n' + largeinput + '' f = codecs.open("largeinput.txt", "wb", "utf-8") f.write(largeinput.strip()) f.close()