Python concatenate text files

后端 未结 12 1947
無奈伤痛
無奈伤痛 2020-11-22 02:51

I have a list of 20 file names, like [\'file1.txt\', \'file2.txt\', ...]. I want to write a Python script to concatenate these files into a new file. I could op

12条回答
  •  爱一瞬间的悲伤
    2020-11-22 03:06

    outfile.write(infile.read()) # time: 2.1085190773010254s
    shutil.copyfileobj(fd, wfd, 1024*1024*10) # time: 0.60599684715271s
    

    A simple benchmark shows that the shutil performs better.

提交回复
热议问题