Creating a temporary file in Python



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()

Thanks for your help.

.



Relevant Pages

  • 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)
  • Re: XP Upgrade from Win2k Pro is a NIGHTMARE
    ... the original temporary file still there on the disk. ... I chose to upgrade from Win2k rather than install anew. ... This crash removes Windows Explorer forcing a ... windows to allow me to copy my data to CD before I attempt a complete ...
    (microsoft.public.windowsxp.setup_deployment)
  • Re: Great SWT Program
    ... to save out a snippet to a temporary file. ... clipboard extremely fragile. ... slower way such as holding down del, or paste at one end of the area ... compared to doing this in Windows. ...
    (comp.lang.java.programmer)