0

I am iterating through a list creating a bunch of temporary files at every iteration. At the end of the loop, I would like to append all these temporary files to a main temporary file. How do I append temporary files?

My attempt is below:

    download_file = NamedTemporaryFile(mode='a')
    for i in range(num_files):
        temp_file = NamedTemporaryFile(mode='w+b')
        # do some stuff
        download_file.write(temp_file)
    return download_file
Bryce Ramgovind
  • 3,127
  • 10
  • 41
  • 72
  • Does this answer your question? [Python append multiple files in given order to one big file](https://stackoverflow.com/questions/5509872/python-append-multiple-files-in-given-order-to-one-big-file) – Mr Alihoseiny Apr 01 '20 at 10:55
  • Why not just write to both files...? If you want to do this with a single `.write()` command, you can abstract it by just creating a wrapper class, e.g. `class Tee: def write(*args): self.file_a.write(*args); self.file_b.write(*args)` – Mateen Ulhaq Apr 01 '20 at 10:56

0 Answers0