[Python-3000] gc, timestamping

Jim Jewett jimjjewett at gmail.com
Thu Jan 25 15:55:31 CET 2007


On 1/24/07, Giovanni Bajo <rasky at develer.com> wrote:
> On 24/01/2007 21.19, Guido van Rossum wrote:

> > (For example, I looked briefly into making os.listdir() an iterator,
> > but decided against it because you'd have a file descriptor open while
> > iterating, and the list is never truly long.)

> What is so wrong about having a file descriptor open while iterating? I can't
> help but thinking of "for L in open(...)" which works out pretty well.

Directories are a special case. Iteration over a file probably won't
cause you to need additional file descriptions. Iteration over a
directory often will, and the function is likely to be called
recursively, like the various *.walk functions. Using up one file
descriptor to keep memory use low is reasonable. Using up ten may not
be, unless directories are truly huge.
-jJ


More information about the Python-3000 mailing list

AltStyle によって変換されたページ (->オリジナル) /