os.remove & os.rmdir

Padraig Brady padraig.brady at corvil.com
Tue Jan 7 05:53:02 EST 2003


In python os.remove() and os.unlink() are synonomous.
This is incorrect for ISO C. The diff is that
remove() also removes empty dirs (like rmdir).

I've checked this on Solaris 8, FreeBSD 4.6 and Linux (glibc 2).
and the standard details:
http://www.opengroup.org/onlinepubs/007904975/functions/remove.html

So, should I do a simple patch?

Advantages I can see are:

    1. It follows the standard
    2. It removes the redundancy of 2 functions doing the same thing
    3. Is saves you having to write code like:
        If os.path.isdir(path):
            os.rmdir(path)
        else:
            os.unlink(path)

Disadvantages:

    1. Backwards compatability (minor I think)

cheers,
Pádraig.





More information about the Python-list mailing list