Problems with os.walk

Scott David Daniels Scott.Daniels at Acm.Org
Thu May 8 08:50:42 EDT 2008


Hrvoje Niksic wrote:
> <Dominique.Holzwarth at ch.delarue.com> writes:
> 
>>     (dirpath, dirnames, filenames) = os.walk(scriptPath)
> 
> You're supposed to loop over values in different directories, like
> this:
> 
> for dirpath, dirnames, filenames in os.walk(scriptPath):
>     ... handle dirpath with dirnames and filenames ...
> 
> The loop will be executed for each subdirectory (direct and indirect)
> of scriptPath.

And if you are simply hand-experimenting, try somthing like:
     generator = os.walk(scriptPath)
     dirpath, dirnames, filenames = generator.next()
     ...
     dirpath, dirnames, filenames = generator.next()
     ...

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list