iMath <redstone-c...@163.com> wrote: >we don't have permission to use the temporary file while it has not >been closed,but when the file is closed , it will be destroyed by >default(delete=True),but once we set delete=False,then we couldn't >depend on the convenience of letting the temporary file automatically >delete itself after it has been used(then we have to delete it later >by os.remove()) ,thus there is nearly no convenience in creating a >temporary file or a persistent one when using NamedTemporaryFile.
In your OP you asked for a platform independent solution thus I don't think it's possible to do what you want if the OS doesn't support opening a file another time while it's still open. Otherwise, on my Linux system this works: >>> import tempfile, subprocess >>> with tempfile.NamedTemporaryFile() as fp: ... fp.write(b"foo\nbar\nbaz\n") ... fp.flush() ... subprocess.call(["cat", fp.name]) ... 12 foo bar baz 0 Bye, Andreas -- https://mail.python.org/mailman/listinfo/python-list