Python append multiple files in given order to one big file

前端 未结 10 825
时光说笑
时光说笑 2020-11-29 06:00

I have up to 8 seperate Python processes creating temp files in a shared folder. Then I\'d like the controlling process to append all the temp files in a certain order into

10条回答
  •  日久生厌
    2020-11-29 06:48

    Just using simple file IO:

    # tempfiles is a list of file handles to your temp files. Order them however you like
    f = open("bigfile.txt", "w")
    for tempfile in tempfiles:
        f.write(tempfile.read())
    

    That's about as OS agnostic as it gets. It's also fairly simple, and the performance ought to be about as good as using anything else.

提交回复
热议问题