tags:

views:

223

answers:

3

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
os.remove(os.path.expanduser("~/.emacs"))
J.F. Sebastian
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
+4  A: 

It sounds like what you really want is a temp file: http://docs.python.org/library/tempfile.html

daharon