I want to delete the file filename if it exists. Is it proper to say
filename
if os.path.exists(filename): os.remove(filename)
Is
Matt's answer is the right one for older Pythons and Kevin's the right answer for newer ones.
If you wish not to copy the function for silentremove, this functionality is exposed in path.py as remove_p:
silentremove
from path import Path Path(filename).remove_p()