reading directory entries one by one

Michael P. Soulier msoulier at nortelnetworks.com_.nospam
Wed May 22 13:39:18 EDT 2002


On Wed, 22 May 2002 09:57:51 -0600, Andrew Dalke <dalke at dalkescientific.com>
wrote:
> 
> "efficient"?  What does that mean in this context?  There are three
> metrics I can think of:
>  - development time, but a list is far easier to understand and use than
>      an iterator.  Eg, to sort given an iterator you need to put it in
>      a list() first.
> 
>  - memory size, for 4000+ files at, oh, 40 bytes per name/string is
>      160K.  Which is about 1/10 of what Python is using, and less than
>      1/1000th of what most machines have.
> 
>  - run time, it's likely faster for Python to build one list in a
>      go than have the iterator overhead
    
    I was thinking memory. Development time is not really an issue, since
adding in opendir() and readdir() would mean 2 lines of code instead of one
during use. 

for file in os.listdir(dir):

dirhandle = os.opendir(dir)
for file in dirhandle.next():

    Something like that...

    Or maybe just...

for file in os.xlistdir(dir):

    Mike

-- 
Michael P. Soulier, QX41, SKY  Tel: 613-765-4699 (ESN: 39-54699)
Optical Networks, Nortel Networks, SDE Pegasus
"...the word HACK is used as a verb to indicate a massive amount
of nerd-like effort."  -Harley Hahn, A Student's Guide to Unix



More information about the Python-list mailing list