msg243149 - (view) |
Author: Taylor Marks (Taylor.Marks) |
Date: 2015-05-14 03:36 |
When you have a file that you don't think you need anymore, the proper thing to do with it is move it to the Trash (or Recycling Bin, if you're on Windows.) The standard library, however, doesn't offer any way of doing this currently. Instead, the only thing it offers is the ability to delete files. Deleting files is a potentially dangerous operation. A novice programmer may end up carelessly delete the wrong file. I would suggest adding in a new function which allows for cross-platform moving of files to trash. It could go into the existing shutil or os modules. Or it could get its own module (like glob). It could be based upon (or even be exactly) this implementation: https://pypi.python.org/pypi/Send2Trash https://github.com/hsoft/send2trash Afterwards, the docs for os.remove and shutil.rmtree could have a warning added that suggests that instead of using such dangerous functions, it may be best for the user to use the new function. (If this is not the place to propose additions to the standard library, please redirect me for where I should go instead. PEP 5 covers how the language should evolve, but then only has a link to bugs.python.org.) |
|
|
msg243173 - (view) |
Author: R. David Murray (r.david.murray) *  |
Date: 2015-05-14 10:59 |
Heh, dangerous is in the eye of the beholder. I don't even have a trash bin on my system (no desktop, just X and shell windows). It is almost always the case that an application written in python that wants to get rid of a file *does* want to really delete it, because it is not operating on user-facing files. It is only when the program is implementing a GUI (and very occasionally when implementing a CLI) that it might want to move something to trash instead. I'm -1 on this proposal. Most python programs aren't GUI programs, so I don't think any significant fraction of python programs need it, and thus that the ones that do can just include it as a dependency along with all the other dependencies they need. (Yes, you can write a full GUI just using tkinter, but the number of GUI programs that have no non-stdlib dependencies is probably quite small.) This is the kind of thing that would need to go to python-ideas first in any case, so I'm going to close the issue. If you get consensus that it is a good idea on the python-ideas mailing list, you can re-open the issue. |
|
|
msg243197 - (view) |
Author: Steven D'Aprano (steven.daprano) *  |
Date: 2015-05-14 15:42 |
This has been discussed on Python-Ideas some time ago, possibly more than once. See here for one such (short) discussion: https://mail.python.org/pipermail/python-ideas/2013-April/020148.html I think that move-to-trash functionality is quite useful, I needed something like that the other day, but there are at least two trash systems on Linux (although one is quite old and may not be used in recent systems), plus Windows, OS X, Android, iOS, etc. So it isn't a trivial piece of code, and it should spend some time as a third-party module first, at least until it reaches a stable and mature state. Since it's been more than two years since the discussion above, perhaps it is worth considering it again (assuming that the library is stable and mature). Are you interested in taking this discussion to python-ideas? |
|
|
msg243220 - (view) |
Author: Virgil Dupras (vdupras)  |
Date: 2015-05-14 22:03 |
For further references, there's also https://mail.python.org/pipermail/python-ideas/2014-December/030547.html which is a deeper discussion and brings even more arguments against it. Even though I'd love to have some of my code integrated into the core, arguments against its inclusion are pretty strong. |
|
|