Creating a temporary file in Python
Sion Arrowsmith
siona at chiark.greenend.org.uk
Wed Oct 31 09:16:38 EDT 2007
looping <kadeko at gmail.com> wrote:
>I want to create a temporary file, read it in an external command and
>finally delete it (in Windows XP).
>
>I try to use tempfile module but it doesn't work, the file couldn't be
>open by my other process (error like: SP2-0310: unable to open file "c:
>\docume~1\looping\locals~1\temp\tmpau81-s.sql")
You're using NamedTemporaryFile. The tempfile documentation
(http://docs.python.org/lib/module-tempfile.html) says:
" [ ... ] Whether the name can be used to open the file a second time,
while the named temporary file is still open, varies across platforms
(it can be so used on Unix; it cannot on Windows NT or later)."
You probably want to use tempfile.mkstemp and explicitly close
(before running the external command) and delete it.
--
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arthur C. Clarke
her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
More information about the Python-list
mailing list