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 terry.reedy
Recipients Elijah Rippeth, pitrou, serhiy.storchaka, terry.reedy
Date 2021-05-21.16:32:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1621614759.34.0.961076981627.issue44069@roundup.psfhosted.org>
In-reply-to
Content
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')
History
Date User Action Args
2021-05-21 16:32:39terry.reedysetrecipients: + terry.reedy, pitrou, serhiy.storchaka, Elijah Rippeth
2021-05-21 16:32:39terry.reedysetmessageid: <1621614759.34.0.961076981627.issue44069@roundup.psfhosted.org>
2021-05-21 16:32:39terry.reedylinkissue44069 messages
2021-05-21 16:32:39terry.reedycreate