Message394125
I agree that from the outside is seems slightly bizarre to make an internal list to implement a function documented as returning an iterator. However, list(scandir) was added by Serhiy in #26032 with the comment that it made globbing 1.5-4 times faster. This is, of course, if one runs the iterator to completion, as is the normal use.
For your presented use case, I suggest something like the following:
next(f for f in scandir(path) if os.path.splitext(f)[1] == '.txt') |
|
Date |
User |
Action |
Args |
2021-05-21 16:32:39 | terry.reedy | set | recipients:
+ terry.reedy, pitrou, serhiy.storchaka, Elijah Rippeth |
2021-05-21 16:32:39 | terry.reedy | set | messageid: <1621614759.34.0.961076981627.issue44069@roundup.psfhosted.org> |
2021-05-21 16:32:39 | terry.reedy | link | issue44069 messages |
2021-05-21 16:32:39 | terry.reedy | create | |
|