[Python-ideas] find-like functionality in pathlib

Guido van Rossum guido at python.org
Tue Jan 5 15:21:09 EST 2016


On Tue, Jan 5, 2016 at 8:37 AM, Chris Barker - NOAA Federal <
chris.barker at noaa.gov> wrote:

> > Note that the PEP doesn't mention rglob() -- why do we even have it? It
> seems rglob(pat) is exactly the same as glob('**/' + path) (assuming os.sep
> is '/'). No TOOWTDI here?
>
> Much as I believe in TOOWTDI, I like having rglob(). "**/" is the kind
> of magic a newbie ( like me :-) ) would have research and understand.
>

Sure. It's too late to remove it anyway.

Is there anything actionable here besides fixing the PermissionError and
the behavior under symlink loops? IMO if you want files only or directories
only you can just add a filter using e.g. is_dir():

p = pathlib.Path.cwd()
real_dirs =  [p for p in p.rglob('*') if p.is_dir() and not p.is_symlink()]

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20160105/d646603b/attachment.html>


More information about the Python-ideas mailing list