os.path.walk

Steve Holden steve at holdenweb.com
Wed Apr 13 07:29:59 EDT 2005


Tony Meyer wrote:
>>If I have os.path.walk(name, processDirectory, None) and 
>>processDirectory needs three arguments how can I ass them 
>>because walk only takes 3?
> 
> 
> Assuming that processDirectory is a function of yours that returns a bool,
> then you'd do something like:
> 
>   os.path.walk(name, processDirectory(a,b,c))
> 
> Where a, b, and c are the arguments that processDirectory requires.  (You
> can add the None parameter to the os.path.walk call, but it won't change
> anything, since it's the default).
> 
Tony:

I think if you try this you will find that it doesn't work because 
os.path.walk will try to call the *result* of processDirectory(a,b,c) 
for each directory in the path.

You could, however, write a doDirectory() function that called 
processDirectory() when os.path.walk called *it*.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list