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

Ram Rachum ram at rachum.com
Thu Jan 1 13:43:09 CET 2015


I take your point about it not being in the `os` module, I have no issue
with it being in shutil or pathlib.

I also agree about the name, "recycle" doesn't really make sense.

Regarding your question: "But I'm still not sure that this needs to be in
the standard library. For such a specialist need, what's wrong with using a
third party solution?"

Well, I can use a third-party solution for everything, but it would be
nicer for me if it was in the standard library because then I could count
on it always being there and the API not changing. I could say the same
thing you said about the `webbrowser` module, that opening a new browser
tab is quite a specialist need, but I do enjoy having it available in the
standard library and I feel the same about sending a file to trash, which I
think is a basic feature that's we've all been taking for granted for the
last decade or two.


Happy new year,
Ram.

On Thu, Jan 1, 2015 at 2:35 PM, Steven D'Aprano <steve at pearwood.info> 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.
>
> (The actual implementation for the move_to_trash function could come
> from another, platform-specific, module.)
>
>
> > if os.RECYCLE_BIN_SUPPORT:
> >     os.recycle(my_file)
> > else:
> >     os.remove(my_file)
>
>
> "Recycle" is not a good name for the function, because it doesn't
> recycle the file. It does the opposite of recycle: it prevents the file
> from being deleted and over-written. I think an explicit name like
> move_to_trash is better than something misleading like "recycle".
>
> No need for a special flag to check if the function exists, just check
> for the function:
>
> try:
>     f = shutil.send_to_trash
> except AttributeError:
>     f = os.remove
> f(my_file)
>
>
> But I'm still not sure that this needs to be in the standard library.
> For such a specialist need, what's wrong with using a third party
> solution?
>
>
> --
> 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/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150101/87e2b1a6/attachment.html>


More information about the Python-ideas mailing list