Python concatenate text files

后端 未结 12 2144
無奈伤痛
無奈伤痛 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:04

    I don't know about elegance, but this works:

        import glob
        import os
        for f in glob.glob("file*.txt"):
             os.system("cat "+f+" >> OutFile.txt")
    

提交回复
热议问题