Christian Heimes added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue29573>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to