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

Andrew Barnert abarnert at yahoo.com
Thu Jan 1 16:37:52 CET 2015


On Jan 1, 2015, at 11:37, Ram Rachum <ram at rachum.com> wrote:

> Hi everyone,
> 
> I'm a complete ignoramus when it comes to Mac, so I can't say anything about that, but as I understand the discussion, there are problems with implementing this on Mac. Okay. So maybe this should be available only on Windows and Linux? (If it's not a problem to do on Linux.)

On Linux, it's not exactly like Mac, but it's similar. Linux has no notion of trash at all; desktop environments like GNOME do. And if you want it to work exactly like the way GNOME does, you call the API via GObject; otherwise you have to implement a complicated approximation based on rename that won't be fully functional.

Really, on all three platforms, the answer is the same: you call an API from your desktop manager. The only difference is that Windows merges desktop and kernel together to the point where they can't be separated--so Python is already using Win32, unlike Cocoa or GObject.

> As much as I don't like having functionality that's only available on certain OSs, it makes more sense than depriving Windows users of functionality that they could be using just because Mac doesn't support it.

No one is "depriving" Windows users of anything. Python comes with pip, send2trash installs without needing a compiler (at least I hope so; if not, someone can write a new third-party module that does). Not everything needs to be in the stdlib. So far, there aren't many third-party modules mentioned in the stdlib docs, but that's only because we didn't have preinstalled pip, wheels, etc. until 3.4.

> (And of course, Python has lots of OS-specific modules.)
> 
> 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: 
> 
> if os.RECYCLE_BIN_SUPPORT:
>     os.recycle(my_file)
> else:
>     os.remove(my_file)
> 
> What do you think? 

There's no such flag for anything else platform-contingent. EAFP.

> 
> 
> Thanks,
> Ram.
> 
> On Thu, Jan 1, 2015 at 1:14 AM, Steven D'Aprano <steve at pearwood.info> wrote:
>> On Wed, Dec 31, 2014 at 11:50:04AM +0100, Andrew Barnert wrote:
>> > On Dec 31, 2014, at 0:47, Steven D'Aprano <steve at pearwood.info> wrote:
>> 
>> > > What's wrong with asking the Finder to move the file? Under what
>> > > circumstances would that be unacceptable? Are there scenarios on OS X
>> > > where the Finder isn't available but the trash is?
>> >
>> > I already answered this briefly earlier in the thread, but in more detail:
>> [...]
>> 
>> Thank you for the detailed and extensive answer!
>> 
>> 
>> --
>> Steven
>> _______________________________________________
>> 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/
> 
> _______________________________________________
> 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/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150101/d38e6d4e/attachment.html>


More information about the Python-ideas mailing list