Re: Creating a temporary file in Python



looping wrote:

Hi,

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")
Is there a way to make it work or I have to manually manage
everything ?

My non working code:

f = tempfile.NamedTemporaryFile(suffix='.sql')
f.write(txt)
f.flush()
p = subprocess.Popen([SQL_PLUS, '-s', dsn, '@', SQL_PLUS_SCRIPT,
f.name],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
p.wait()
f.close()

I'm not an expert, but I think you need to close the file first - you under
windows here, which can be picky about such stuff AFAIK. Or maybe there is
some other mode-specifier.

Diez
.



Relevant Pages

  • Creating a temporary file in Python
    ... 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, ...
    (comp.lang.python)
  • Re: Clock on pc time loss
    ... Time loss with a fresh battery will be very small (a few milliseconds ... Ken Blake - Microsoft MVP Windows: ... operable program or batch file. ... 'cmd' is not recognized as an internal or external command, ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: File-writing not working in Windows?
    ... and written to the temporary file in tempdir. ... It does not work in Windows. ... Can anyone tell me what it is that I'm missing which would prevent the ... cutting an HTML file at predetermined comment sections, ...
    (comp.lang.python)
  • Re: Problems Creating Temporary File
    ... After cleaning up a good deal of residual muck left over from a previous exercise relating to "read-only" and "hidden", I found that Windows leaves folders marked "read only" even after changing all the files. ... Sure enough, the temporary folder KGxxRpbcuU is so marked, and I'm guessing that might be your problem, although the file has indeed been created, and the whole shooting match can indeed be deleted manually. ... it is sensitive to Perl ... All I need is to create a temporary file to store some data so I can ...
    (perl.beginners)
  • Re: Explorer loses focus on current file
    ... When a previously saved file is opened for editing, printing, or review, Word creates a temporary file with a .doc file name extension that begins with a tilde "~" followed by a dollar sign "$" followed by the remainder of the original file name. ... I start in Windows Explorer, browsing a folder. ... Paint Shop PRO 7 also jumps like this when opening files. ...
    (microsoft.public.windowsxp.basics)