file bug???

Peter Otten __peter__ at web.de
Fri Nov 21 03:49:22 EST 2003


Anand Pillai wrote:

> Some other things.
> 
> o 'os' module does not have a function 'walk'. Change it to os.path.walk .
> o  os.path.walk takes 3 arguments, not one. You need to correct this.

Python 2.3.2 (#1, Oct 21 2003, 10:03:19)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.walk
<function walk at 0x40279a3c>
>>>

Welcome to Python 2.3 :-)

IMHO the new os.walk() generator is *much* better than os.path.walk() and I
expect that os.path.walk() will no longer occur in new code.
Most common usage pattern:

for dirpath, dirnames, filenames in os.walk(rootdir):
    # proces files/subdirectories here

The gain in explicitness is comparable to list comprehension vs map().

Peter




More information about the Python-list mailing list