Re: Creating a temporary file in Python



On Oct 31, 2:16 pm, Sion Arrowsmith <si...@xxxxxxxxxxxxxxxxxxxxxx>
wrote:
" [ ... ] 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)."

I didn't notice this limitation when reading the doc, thanks to point
me to it.

So for the future newbie that look something like this, here is my
final code:

fd, filename = tempfile.mkstemp(suffix='.sql')
f = os.fdopen(fd, 'wb')
try:
f.write(txt.encode('cp1252'))
f.close()
p = Popen([SQL_PLUS, '-s', dsn,
'@', SQL_PLUS_SCRIPT, filename],
stdout=PIPE, stderr=STDOUT)
p.wait()
finally:
os.remove(filename)


.



Relevant Pages

  • Re: Windows Media Player executes WMF content in .MP3 files.
    ... >In the UNIX world, how a file is executed always depends on any magic ... and never on the filename. ... In the Microsoft world, the file extension counts to decide what operations ...
    (comp.security.misc)
  • Re: Request description of UFS for VMS person
    ... Most Unix books at least touch on the subject. ... mostly the same as in VMS: a one-to-one mapping of filenames to inode ... requested filename, learns its FID, goes to INDEXF.SYS finds the VBN ... finally reads the file header with that number. ...
    (comp.os.vms)
  • Re: (pathname "/tmp/foo/bar/") vs (pathname "/tmp/foo/bar")
    ... colon in it to scp and see what happens. ... named unix you might just insist that any filename with a colon in it ... must be prefix with unix:. ... think what is at issue here is: Who and what are namestrings really ...
    (comp.lang.lisp)
  • Re: Migrating Matlab files from Windows to UNIX
    ... distinguish \ between part of a filename r a dir sep. ... But Matlab could have prevented this. ... One company wanted a Windows version, ... others wanted on UNIX. ...
    (comp.soft-sys.matlab)
  • Re: Migrating Matlab files from Windows to UNIX
    ... Michael Wild wrote: ... distinguish \ between part of a filename r a dir sep. ... One company wanted a Windows version, ... others wanted on UNIX. ...
    (comp.soft-sys.matlab)