Message290642
Raymond, I think Richard's approach is problematic at best.
Richard, you cannot use a NamedTempFile with an external process like that. At least you have to flush the file to disk. Even flushing is not safely portable. The safest and most portable approach is to close the file, call the other process and then unlink the file manually:
with tempfile.NamedTemporaryFile(delete=False) as f:
try:
f.write(b'data')
f.close()
subprocess.Popen(['binutil', f.name, ...])
finally:
os.unlink(f.name)
It's too bad that close() on a NamedTemporaryFile(delete=True) deletes the files. For your problem it would be beneficial to have __exit__() perform the unlink operation. |
|
Date |
User |
Action |
Args |
2017-03-27 20:27:37 | christian.heimes | set | recipients:
+ christian.heimes, rhettinger, jwilk, andrewnester, richardxia |
2017-03-27 20:27:37 | christian.heimes | set | messageid: <1490646457.25.0.814103945064.issue29573@psf.upfronthosting.co.za> |
2017-03-27 20:27:37 | christian.heimes | link | issue29573 messages |
2017-03-27 20:27:37 | christian.heimes | create | |
|