Message337339
| 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:54 | cheryl.sabella | set | recipients:
+ cheryl.sabella, terry.reedy, Al.Sweigart |
| 2019年03月06日 20:21:54 | cheryl.sabella | set | messageid: <1551903714.6.0.269402165075.issue23205@roundup.psfhosted.org> |
| 2019年03月06日 20:21:54 | cheryl.sabella | link | issue23205 messages |
| 2019年03月06日 20:21:54 | cheryl.sabella | create |
|