Temp File in Context Manager
import tempfile
with tempfile.TemporaryFile() as fp:
fp.write(b'Hey Toronto')
fp.seek(0)
print(fp.read())
b'Hey Toronto'
fp
<_io.BufferedRandom name=59>
fp.read()
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-8-5b707e20d623> in <module>()
----> 1 fp.read()
ValueError: read of closed file
# As you can see the error, the file is already closed. So, you can't read anymore