<div>fnmatch.filter does Unix filename pattern matching.</div><div><a href="https://docs.python.org/3/library/fnmatch.html#fnmatch.filter">https://docs.python.org/3/library/fnmatch.html#fnmatch.filter</a></div><div><br></div><div>grin and grind are like grep and find with options to filter hidden files and VCS directories by default.</div><div><a href="https://pypi.org/project/grin/">https://pypi.org/project/grin/</a></div><div><br></div><div>There's an example of using the Python API here:</div><div><a href="https://github.com/rkern/grin/blob/master/examples/grinpython.py">https://github.com/rkern/grin/blob/master/examples/grinpython.py</a></div><div><br></div><div>- grin.get_regex(args)</div><div>- grin.get_filenames(args)</div><div><br></div><div><a href="https://github.com/rkern/grin/blob/master/grin.py">https://github.com/rkern/grin/blob/master/grin.py</a></div><br>On Wednesday, May 9, 2018, Steve Barnes <<a href="mailto:gadgetsteve@live.co.uk">gadgetsteve@live.co.uk</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
<br>
On 08/05/2018 15:53, Giampaolo Rodola' wrote:<br>
> <br>
> <br>
> On Tue, May 8, 2018 at 2:00 PM, David Mertz <<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a> <br>
> <mailto:<a href="mailto:mertz@gnosis.cx">mertz@gnosis.cx</a>>> wrote:<br>
> <br>
>     I like the idea. I think an argument to os.walk() is the simplest<br>
>     option for most users. But per some comments, "hidden" is actually<br>
>     more subtle than the filesystem bit sometimes. I.e. dot-files, ~<br>
>     suffix, maybe .bak, etc.<br>
> <br>
>     I'd suggest meeting the ideas slightly and making the new argument<br>
>     'filter' or 'skip' that takes a callable. Default to None, but<br>
>     provide an os.is_hidden that users don't need to figure out how to<br>
>     implement. E.g.<br>
> <br>
>     os.walk(PATH, skip=os.is_hidden)<br>
> <br>
>     os.walk(PATH, skip=lambda entry: entry.name.endswith(('~', '.bak',<br>
>     '.tmp')))<br>
> <br>
> <br>
> I think this would be a good addition because it gives direct access to <br>
> the underlying os.scandir() objects which are currently inaccessible and <br>
> discarded (if os.walk() were to be written today it'd probably yield <br>
> (root, os.DirEntry) instead of (root, dirs, files)). As such one can <br>
> implement advanced filtering logic without having to call os.stat() for <br>
> each path string yielded by os.walk() (faster).<br>
> <br>
> IMO the callback should accept a (root, os.DirEntry) pair though, <br>
> because the "root" path can also be part of the filtering logic.<br>
> <br>
> -- <br>
> <br>
> Giampaolo - <a href="http://grodola.blogspot.com" target="_blank">http://grodola.blogspot.com</a><br>
> <br>
> <br>
<br>
I like the idea of extending the original idea to a filtered walk <br>
possibly with some predefined filters.<br>
<br>
As there does not seem to be a lot of strong opposition so far to the <br>
basic idea, (other than a some "why bother it is too easy to do <br>
yourself"), it seems like there is a choice now is between:<br>
<br>
   a) raising an enhancement request on the tracker (I am not sure if <br>
this is major enough to require a PEP) or<br>
   b) setting up a new library on PyPi and putting it out there to see <br>
if it sinks or swims.<br>
<br>
What is the general feeling between the two options?<br>
<br>
-- <br>
Steve (Gadget) Barnes<br>
Any opinions in this message are my personal opinions and do not reflect <br>
those of my employer.<br>
<br>
---<br>
This email has been checked for viruses by AVG.<br>
<a href="http://www.avg.com" target="_blank">http://www.avg.com</a><br>
<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote>