[Python-ideas] pathlib suggestions

Todd toddrjen at gmail.com
Tue Jan 24 15:30:34 EST 2017


I have been using pathlib, and I have come up with a few suggestions on
what would make the module more useful for me (and hopefully others):

First, for me, extensions are primarily useful as a single unit.  So,
practically speaking, the extension of "spam.tar.gz" isn't ".gz", it is
".tar.gz".  So it would be nice to have some properties to make it easier
to deal with the "complete" extension like this.  There is a "suffixes"
property, but it returns a list, which you then have to recombine
manually.  And as far as I can tell there is no method to return the name
without any extension.  And there is no method for replacing all the
extensions at once.

So although the names are tentative, perhaps there could be a "fullsuffix"
property to return the extensions as a single string, a "nosuffix"
extension to return the path without any extensions, and a "with_suffixes"
method that replaces all the suffix and can accept multiple arguments
(which would then be joined to create the extensions).

Second, for methods like "rename" and "replace", it would be nice if there
was an "exist_ok" argument that defaults to "True" to allow for safe
renaming.

Third, it would be nice if there was a "uid" and "gid" method for getting
the numeric user and group IDs for a file, or alternatively a "numeric"
argument for the "owner" and "group" methods.

Fourth, for the "is_*" methods, it would be nice if there was a "strict"
argument that would raise an exception if the file or directory doesn't
exist.

Finally, although not problem with the module per se, the example for the
"parts" property should probably show at least one file with an extension,
to make it clear how it deals with extensions (since the documentation is
ambiguous in this regard).

Thanks for your time.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170124/3c97188d/attachment.html>


More information about the Python-ideas mailing list