I would like to remove two files from a folder at the conclusion of my script. Do I need to create a function responsible for removing these two specific files? I would like to know in some detail how to use os.remove (if that is what I should use) properly. These two files will always be discarded at the conclusion of my script (which packages a series of files together in a zip format). Thanks in advance.
A:
Just call os.remove("path/to/file")
. For example, to remove the file .emacs
, call
os.remove(".emacs")
The path should be a str
that's the pathname of the file. It may be relative or absolute.
mipadi
2008-11-17 18:58:58
os.remove(os.path.expanduser("~/.emacs"))
J.F. Sebastian
2008-11-18 17:01:34
A:
It is perfectly acceptable to have a 'cleanup()' function that you call at the end of your script, which will call 'os.remove()' on your files.
Martin Cote
2008-11-17 18:59:19
+4
A:
It sounds like what you really want is a temp file: http://docs.python.org/library/tempfile.html
daharon
2008-11-17 19:08:30