[Python-Dev] PEP 428 - pathlib API questions

Nick Coghlan ncoghlan at gmail.com
Mon Nov 25 04:15:57 CET 2013


On 25 Nov 2013 09:42, "Ben Hoyt" <benhoyt at gmail.com> wrote:
>
> > Using "**" for directory spanning globs is also another case of us
borrowing
> > a reasonably common idiom from *nix systems that may not be familiar to
> > Windows users.
>
> Okay, *nix wins then. :-) Python's stdlib is already fairly
> *nix-oriented (even when it's being cross-platform), so I guess it's
> not a big deal.
>
> My only remaining concern then is that there shouldn't be more than
> one way to do recursive globbing in a new API like this. Why does
> rglob() exist when the documentation simply says "like calling glob()
> but with '**' added in front of the pattern"?
>
> http://docs.python.org/dev/library/pathlib.html#pathlib.Path.rglob

Because it's a layered API - embedding ** in the pattern is a strictly more
powerful interface, but can be a little tricky to get your head around
(especially if you don't use a shell that has the feature). rglob() is
simpler, but not as flexible.

We offer that kind of multi-level API fairly often. For example,
subprocess.call() and friends are simpler interfaces for particular ways of
using the powerful-but-complex subprocess.Popen API. The metaprogramming
stack (functions, classes, decorators, descriptors, metaclasses) similarly
offers the ability to trade increased complexity for increases in power and
flexibility.

In these cases, the "obvious way" is to use the simplest API that covers
the use case, and only reach for the more complex API when you genuinely
need it.

Cheers,
Nick.

>
> -Ben
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131125/b067d92e/attachment.html>


More information about the Python-Dev mailing list