This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
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
process
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 2022-04-11 14:58 by admin.

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 (https://docs.python.org/3/library/pathlib.html#correspondence-to-tools-in-the-os-module) for more visibility.

There was a similar thread in python-ideas to add more functions : https://groups.google.com/forum/#!topic/python-ideas/X9Eim6z31Ik

Thanks
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.

Thanks
History
Date User Action Args
2022-04-11 14:58:59adminsetgithub: 77375
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