Concatenate multiple files into a single file object without creating a new file

前端 未结 8 2282
迷失自我
迷失自我 2021-02-12 16:37

This question is related to Python concatenate text files

I have a list of file_names, like [\'file1.txt\', \'file2.txt\', ...].

I wou

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-12 17:31

    You can use fileinput package. This module implements a helper class and functions to quickly write a loop over a list of files

    import fileinput
    with fileinput.input(files=('file1.txt', 'file2.txt', 'file3.txt')) as f:
        for line in f:
          #rest code
    

提交回复
热议问题