Python: Difference between os.remove() and os.unlink() and which one to use?

Note: When this question was originally asked, it had a python-2.7 tag, which has since been removed. See the comments of this answer for discussion on the changes made in Python 3.


They are identical as described in the Python 2.7 documentation:

os.remove(path):

Remove (delete) the file path. If path is a directory,
OSError is raised; see rmdir() below to remove a directory. This is
identical to the unlink() function
documented below. On Windows,
attempting to remove a file that is in use causes an exception to be
raised; on Unix, the directory entry is removed but the storage
allocated to the file is not made available until the original file is
no longer in use.

Availability: Unix, Windows.

os.unlink(path):

Remove (delete) the file path. This is the same function as remove();
the unlink() name is its traditional Unix name.

Availability: Unix, Windows.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)