Quick way to save a python TempFile?

python, temporary-files

Solution

Seek to the beginning and use `shutil.copyfileobj()` to copy the data to a file you create.

Problem

I am using `tempfile.TemporaryFile` for some intermediate processing. The program nicely removes the temp file for me when it closes, which is precisely the behaviour that I want the majority of the time. But is there a way to save the file for examination in the event of a (trapped) error or other abnormal circumstance?

Original source

Related problems