tempfile module is available in python 2.7. However tempfile.TemporaryFolder() was introduced in 3.2 That is why you get error there, not earlier when you use tempfile.TemporaryFile().
Few points - you use tempfile.TemporaryFile() to create the file. Note that it will be destroyed immediately when you close it. I think you want to use tempfile.mkstemp() in which case YOU are responsible to delete it after. By default temporary file it is created in the default temp folder for the current OS. In 2.7 you have also tempfile.mkdtemp() which creates temporary directory and again you are responsible to delete it. In short, I think you need to use
Finally, you should move to python3 as python2 support ends 1 Jan 2020.
Few points - you use tempfile.TemporaryFile() to create the file. Note that it will be destroyed immediately when you close it. I think you want to use tempfile.mkstemp() in which case YOU are responsible to delete it after. By default temporary file it is created in the default temp folder for the current OS. In 2.7 you have also tempfile.mkdtemp() which creates temporary directory and again you are responsible to delete it. In short, I think you need to use
mkstemp()
and possibly mkdtemp()
, not the objects directly.Finally, you should move to python3 as python2 support ends 1 Jan 2020.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs