Python concatenate text files

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

    What's wrong with UNIX commands ? (given you're not working on Windows) :

    ls | xargs cat | tee output.txt does the job ( you can call it from python with subprocess if you want)

提交回复
热议问题