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

I have several files in a folder. I want to delete a file after processing it. What is the difference between the two methods? and which method is ideal for my scenario? Thanks!

+6
source share
1 answer

They are identical, as described in the official Python 2.7.13 documentation .

os.remove (path) :

Delete (delete) the file path. If the path is a directory, an OSError is raised; see rmdir () below to remove the directory. This is the identical unlink () function described below. On Windows, an attempt to delete the file that is in use throws an exception. raised; on Unix, the directory entry is deleted, but the storage allocated for the file is not accessible until the original file is no longer used.

os.unlink (path) :

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

+10
source

Source: https://habr.com/ru/post/1015541/


All Articles