[Tutor] Delete file before function ends

Adrian Greyling adrian.greyling at gmail.com
Mon Oct 6 17:31:41 CEST 2008

Greetings all,

Not sure if this is possible, but I'll ask anyway.  Below is a code snippet
that creates my "problem"...  What I'd like to do, is create a plain text
file, use the associated program to open said textfile, (using os.startfile)
and after the associated program has what it needs to open the file and then
of course, has the current focus, I'd like to delete the text file in the
background, so to speak.  (Please assume that the program doesn't lock
'mytextfile.xyz' when it opens it.)

What happens with the code snippet below, is that it doesn't really start
the second program until the function is finished.  I tried using
time.sleep() in between the os.startfile() and os.remove(), but it just
delays opening 'mytextfile.xyz' and actually deletes the file before my
second program can open it up.  Any way around this??

path = "c:\MyFolder\mytextfile.xyz"
#bunch of stuff here to create 'mytextfile.xyz"

Thanks everyone,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20081006/3d4ee09d/attachment.htm>

More information about the Tutor mailing list