Re: Creating a temporary file in Python



On Oct 31, 2:16 pm, "Diez B. Roggisch" <de...@xxxxxxxxxxxxx> wrote:

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

Actually closing the file delete it without any chance to use it...

Well I changed my code this way:

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

I understand the security issues of temporary file (as explained in
Python doc) but maybe standard lib need a NamedTemporaryFile that
could be used by another process.

.



Relevant Pages

  • Re: Creating a temporary file in Python
    ... which can be picky about such stuff AFAIK. ... there is some other mode-specifier. ... Actually closing the file delete it without any chance to use it... ... Python doc) but maybe standard lib need a NamedTemporaryFile that ...
    (comp.lang.python)
  • Re: $40k Audio Equip. Contest -- Last Chance To Enter
    ... Just wanted to give everyone here a heads up that on March 31 i am ... closing the entries for your chance to win your share of over $40,000 ...
    (rec.audio.marketplace)
  • Re: re:Copying locked files
    ... there is AFAIK no chance to read it except with a ... custom I/O driver. ... M S Herfried K. Wagner ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Exchange 5.5 Server in Win2003 Domaene integrieren
    ... Die beiden Domänen befinden ... >sich natürlich auf unterschiedlichen Servern. ... AFAIK keine Chance, wenn beide gleich heißen, ohne eine der beiden platt ...
    (microsoft.public.de.exchange)
  • Re: Win a 2006 F1 testing trip in Barcelona
    ... For your chance to win this fantastic prize, ... Closing date for ... Prev by Date: ...
    (uk.rec.competitions)