In article <mailman.424.1292088328.2649.python-l...@python.org>,
 Christian Heimes <li...@cheimes.de> wrote:

> Am 11.12.2010 18:04, schrieb Roy Smith:
> > if os.access("file", os.F_OK):
> >    os.unlink("file")
> > 
> > but that's annoying too.  What would people think about a patch to 
> > os.unlink() to add an optional second parameter which says to ignore 
> > attempts to remove non-existent files (just like "rm -f")?  Then you 
> > could do:
> 
> -1
> 
> os.unlink is a small wrapper around the unlink(2) function.

OK, fair enough.  Perhaps a better place would be in a higher level 
module like shutil.

It was suggested I look at shutil.rmtree(), but that only works of path 
is a directory.  Also, the meaning of the ignore_errors flag is not 
quite what I'm looking for.  I don't want to ignore errors, I just want 
"if it doesn't exist, this is a no-op".  In short, exactly what "rm -r" 
does in the unix shell.

So, maybe a new function is shutils?

shutils.rm(path, force=False)
Delete the file at path.  If force is True, this is a no-op if path does 
not exist.  Raises OSError if the operation fails.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to