[Python-ideas] os.listdir iteration support

Greg Ewing greg.ewing at canterbury.ac.nz
Fri Nov 23 08:01:43 CET 2007


Adam Atlas wrote:
> On 22 Nov 2007, at 23:59, Aahz wrote:
> 
>>The problem is that reading a directory requires an open file handle;
>>given a generator context, there's no clear mechanism for determining
>>when to close the handle.
> 
> Whenever the generator is __del__ed, or whenever the iteration  
> completes, whichever comes first?

Maybe what we really want is the functionality of
the C opendir and readdir functions exposed in the os
module. Then we could have an explicit method for
closing the file handle.

--
Greg




More information about the Python-ideas mailing list