Re: Creating a temporary file in Python



looping <kadeko@xxxxxxxxx> 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@xxxxxxxxxxxxxxxxxxxxxx -- 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
.



Relevant Pages

  • RE: tempfile.gettempdir() result on Windows
    ... | | On MS Windows, I am trying to find out a good default location to ... | | save some temporary files. ... even have to import the tempfile module if you don't want to. ... anti-virus service working around the clock, around the globe, visit: ...
    (comp.lang.python)
  • tempfile.gettempdir() result on Windows
    ... On MS Windows, I am trying to find out a good default location to ... save some temporary files. ... The tempfile module seemed to have exactly what I wanted: ... Does anybody know how I can obtain a temp directory in 'verbose' ...
    (comp.lang.python)
  • Re: /dev/null as a file-like object, or logging to nothing
    ... Windows has a NUL: device which behaves like /dev/null. ...
    (comp.lang.python)
  • Re: passing argument to script
    ... enclose it in quotation marks otherwise your shell will interfere. ... you need to invoke your program as ... Same is true on Windows. ...
    (comp.lang.python)
  • Re: Creating a temporary file in Python
    ... I want to create a temporary file, read it in an external command and ... I try to use tempfile module but it doesn't work, ... windows here, which can be picky about such stuff AFAIK. ...
    (comp.lang.python)