[Python-ideas] Adding `pathlib.Path` method that would send file to recycle bin
steve at pearwood.info
Mon Jan 5 02:31:23 CET 2015
On Sun, Jan 04, 2015 at 02:24:36PM -0500, random832 at fastmail.us wrote:
> On Fri, Jan 2, 2015, at 20:50, Steven D'Aprano wrote:
> > > Because what _not_ having a
> > > cross-platform wrapper gets you is windows and mac left behind
> > Really? I would expect that Windows is probably the *easiest* platform
> > to implement this functionality, as it has a single, standard, stable
> > API for moving files to trash. (Or so I am lead to believe.) You can
> > probably use that API via ctypes, or via pywin32.
> Why would someone who is developing on Linux and has no pre-made library
> function to call bother with that?
Because they want to write cross-platform code.
For my own personal scripts, I wouldn't bother. If I had a Windows
system which I intended to use the script on, I would, or if I intended
to make the script available to others, I might.
> If being cross-platform isn't easy, it won't happen. You see it now with
> the lack of any support for "call glob on arguments on windows and not
> on unix" [because the shell handles it on unix] whether directly, in
> argparse, or in fileinput - today, nothing ever calls glob, and so
> people calling such scripts on windows can't use wildcards (glob is also
> different from windows wildcards in subtle ways)
I think you are mistaken that nothing uses glob:
> > You have a choice of desktop
> > environments, which may or may not provide a move-to-trash API,
> > including no desktop environment at all. Gnome provides an API for
> > moving to trash, but I don't know how well it supports the freedesktop
> > standard; KDE supports the freedesktop standard, but I don't know if it
> > provides an API that can be called. XFCE has partial support.
> I don't see why you need to call an API to the desktop enviroment.
You don't *need* to do so, but doing so guarantees that your code will
match the expected behaviour as provided by the API, and avoids needing
to re-invent the wheel.
I would expect that for something which eventually makes it into the
standard library, if it ever does, it will have multiple
- call the platform API, if one exists and it is available
- fall back to a Python implementation, if no such API exists
That is exactly what the third party Send2Trash package does. If Gnome
is installed and the GIO library is installed, it uses that, otherwise
it falls back on its own (possibly inferior?) implementation.
More information about the Python-ideas