다음 스크립트를 작성하여 디렉토리의 모든 파일을 하나의 단일 파일로 결합했습니다.디렉토리의 모든 파일을 하나의 파일로 결합하는 python 스크립트
import time, glob
outfilename = 'all_' + str((int(time.time()))) + ".txt"
filenames = glob.glob('*.txt')
with open(outfilename, 'wb') as outfile:
for fname in filenames:
with open(fname, 'r') as readfile:
infile = readfile.read()
for line in infile:
outfile.write(line)
outfile.write("\n\n")
시간에 최적화 되었습니까? "cat * .txt> all.txt"를 사용하십시오 :) –
가능한 복제본 [여러 개의 텍스트 파일을 하나의 텍스트 파일로 결합하여 파이썬 사용] (http://stackoverflow.com/questions/17749058/combine-multiple-text-files- 하나의 텍스트 파일을 사용하는 파이썬) – llb