Title: Path-file objects does not have method to delete itself if its a file
Type: enhancement Stage:
Components: Versions: Python 3.8, Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: njs, rougeth, xtreak
Priority: normal Keywords:

Created on 2018-04-01 02:47 by rougeth, last changed 2018-10-05 16:32 by xtreak.

Messages (5)
msg314756 - (view) Author: Marco Rougeth (rougeth) * Date: 2018-04-01 02:47
Path has the method `.rmdir()` for removing the directory, but it doesn't have anything if it correspond to a file.

The `os.remove` could be used here, but I think it should have a more appropriate/explicit  name like `.rmfile()`.

If it make  sense, I'd be glad to work on it.
msg314758 - (view) Author: Nathaniel Smith (njs) * (Python committer) Date: 2018-04-01 04:33
You're looking for 'Path.unlink'. Agreed though that the name makes it hard to find. (I guess it makes sense to old-school Unix greybeards, but Python does generally try to be useful for more people than just them...) There was some discussion on python-dev a few weeks ago about smoothing over some of these rough edges in the Path API, but it kinda fizzled out without anyone volunteering to do the work of going through and curating a good list of changes and writing down a case for each of them.
msg314773 - (view) Author: Marco Rougeth (rougeth) * Date: 2018-04-01 13:41
Wow, I never saw unlink term related to removing files (obviously I'm not an old-school Unix greybeard). @nsj could you point me the thread you talked about? or  help me find it? I looked in the archive in the last three months and couldn't find it.

Thank you.
msg326108 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-09-22 18:51
Maybe this can be added to list at the end ( for more visibility.

There was a similar thread in python-ideas to add more functions :!topic/python-ideas/X9Eim6z31Ik

msg327150 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2018-10-05 16:32
I have added unlink along with other similar methods in Pathlib as part of issue34825 to the reference table which I hope helps. I propose closing this.

Date User Action Args
2018-10-05 16:32:35xtreaksetmessages: + msg327150
2018-09-22 18:51:12xtreaksetmessages: + msg326108
2018-09-22 18:27:39xtreaksetnosy: + xtreak
2018-04-01 13:41:21rougethsetmessages: + msg314773
2018-04-01 04:33:27njssetnosy: + njs
messages: + msg314758
2018-04-01 02:47:34rougethcreate