import tempfile
import shutil
tmp_f = tempfile.NamedTemporaryFile(delete=False)
tmp_f.write("hello world")
shutil.copy(tmp_f.name, "/etc/exports")
When I read /etc/exports
, it is a completely empty file. what is wrong?
You need to close the file:
tmp_f.write("hello world")
tmp_f.close()