waling a directory with very many files

Terry Reedy tjreedy at udel.edu
Mon Jun 15 15:35:04 EDT 2009


Christian Heimes wrote:
> Terry Reedy wrote:
>> You did not specify version.  In Python3, os.walk has become a generater
>> function.  So, to answer your question, use 3.1.
> 
> I'm sorry to inform you that Python 3.x still returns a list, not a
> generator.

 >>> type(os.walk('.'))
<class 'generator'>

However, it is a generator of directory tuples that include a filename 
list produced by listdir, rather than a generator of filenames 
themselves, as I was thinking. I wish listdir had been changed in 3.0 
along with map, filter, and range, but I made no effort and hence cannot 
complain.

tjr




More information about the Python-list mailing list