This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author cheryl.sabella
Recipients Al.Sweigart, cheryl.sabella, terry.reedy
Date 2019-03-06.20:21:54
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1551903714.6.0.269402165075.issue23205@roundup.psfhosted.org>
In-reply-to
Content
I've opened a PR with the changes.  I did several commits, one for each stage.  That is, the first one adds the test, then the second one moves `findfiles` to the module level, etc.

I added the `onerror` function because if a directory that doesn't exist is entered as the path, it's nice to see that message at the top of the output window instead of just seeing zero hits.  Plus, I had made a test for it.  :-)

One change that I didn't commit is that an alternative version of findfiles would be:

def findfiles(folder, pattern, recursive):
    prefix = '**/' if recursive else ''
    yield from(pathlib.Path(folder).glob(f'{prefix}{pattern}'))

The tests would have to be reworked, but manual testing showed it gave the same results, albeit without the `onerror`.

One other comment about the sorting.  If you change the `sorted()` in `grep_it()` to `list()` when you're looking at manual results, you'll see that `list()` shows all of one directory first, then all of the first child directory, etc (which makes sense since walk does each directory at a time).  It's a quick way to compare the depth-first vs breadth first results.
History
Date User Action Args
2019-03-06 20:21:54cheryl.sabellasetrecipients: + cheryl.sabella, terry.reedy, Al.Sweigart
2019-03-06 20:21:54cheryl.sabellasetmessageid: <1551903714.6.0.269402165075.issue23205@roundup.psfhosted.org>
2019-03-06 20:21:54cheryl.sabellalinkissue23205 messages
2019-03-06 20:21:54cheryl.sabellacreate