os.listdir unwanted behaviour
python.list at tim.thechases.com
Tue Sep 29 11:03:17 CEST 2009
Piet van Oostrum wrote:
>>>>>> Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> (SD) wrote:
>> SD> What you describe is impossible -- os.listdir() returns an ordinary list,
>> SD> it isn't a lazy iterator that updates automatically as the directory
>> SD> changes. (At least not in Python2.5 -- I haven't checked Python 3.1.)
> He's not using Python3, see the print statement and the file function.
> But even with the appropriate changes the behaviour will be the same in
> 3.1 as in 2.x.
I think Steven may be remembering the conversation here on c.l.p
a month or two back where folks were asking to turn os.listdir()
into an iterator (or create an os.xlistdir() or os.iterdir()
function) because directories with lots of files were causing
inordinate slowdown. Yes, listdir() in both 2.x and 3.x both
return lists while such a proposed iterator version could be
changed on the fly by interim file/directory creation.
More information about the Python-list