Creating a temporary file in Python
looping
kadeko at gmail.com
Wed Oct 31 11:34:16 EDT 2007
On Oct 31, 2:16 pm, Sion Arrowsmith <si... at chiark.greenend.org.uk>
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)
More information about the Python-list
mailing list