[Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin

Andrew Barnert abarnert at yahoo.com
Thu Jan 1 16:54:59 CET 2015


On Jan 1, 2015, at 13:47, Markus Unterwaditzer <markus at unterwaditzer.net> wrote:

> On Thu, Jan 01, 2015 at 11:35:26PM +1100, Steven D'Aprano wrote:
>> On Thu, Jan 01, 2015 at 12:37:55PM +0200, Ram Rachum wrote:
>> 
>>> So maybe we can add a function to the `os` module that sends a file to the
>>> recycle bin, and a constant that will say whether the current OS supports
>>> this? Then we could have code like this:
>> 
>> The os module is for low-level operating-system functions. "Send to 
>> trash" is neither low-level nor part of the OS per se, it is part of the 
>> desktop environment.
>> 
>> I'm not convinced that this needs to be in the standard library, but if 
>> it is, I think that the os module is completely the wrong place for it. 
>> I think, in order of preference:
>> 
>> 1) shutil
>> 2) pathlib
>> 
>> is the right place.
> 
> Maybe the right way to do this is to create a new module, stdlib or not, for
> desktop-related APIs. Besides a `recycle` function this might, for example,
> include a subset of pyxdg's functionality.

That's a great idea. To do something as simple as getting special directory names or creating a shortcut/alias/bookmark (as opposed to a symlink) or, yes, trashing a file in a cross-platform way requires something way too heavy-duty (like Qt or JUCE)... or copying code off some blog (that doesn't actually work on localized Windows or in a sandboxed OS X app or on non-Debianish Linux, but you won't know that until you think to test it).

A third-party module can get away with 90% support. Most Mac users are on 10.8+, most apps don't fork, most Linux users who care about the desktop have a GNOME-compatible one; etc.

> 
> -- Markus
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list