[issue11406] There is no os.listdir() equivalent returning generator instead of list

Vetoshkin Nikita report at bugs.python.org
Wed Mar 9 22:21:25 CET 2011


Vetoshkin Nikita <nikita.vetoshkin at gmail.com> added the comment:

>We could, but someone must:
>1) provide a patch
While working on a straightforward patch for linux, I had to make a lot of copy-paste job. posixmodule.c is quite a mess already :(
>2) demonstrate a significant improvement in some real-world situation
suppose we have a directory with several millions of files and a cron script which must process just a bunch of them at a time. There's no need to gather them all.
As mmarkk mentioned - readdir already provides generator style access to the directory contents, it could be nice to provide such API in Python.

http://pastebin.com/NCGmfF49 - here's a kind of test (cached and uncached)
http://pastebin.com/tTKRTiNc - here's a testcase for batch processing of directory contenst (first is xlistdir(), second - listdir()) both uncached.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11406>
_______________________________________


More information about the Python-bugs-list mailing list