[melbourne-pug] os.walk into a skip

John Machin sjmachin at lexicon.net
Wed Mar 3 06:56:37 CET 2010


On 3/03/2010 4:18 PM, Tobias Sargeant wrote:
> 
> On 03/03/2010, at 4:09 PM, Mike Dewhirst wrote:
> 
>> Hi all
>>
>> Can someone tell me how to skip some arbitrary directories in os.walk()?
> 
> 
> from the os.walk() docstring:
> 
>     When topdown is true, the caller can modify the dirnames list in-place
>     (e.g., via del or slice assignment), and walk will only recurse into 
> the
>     subdirectories whose names remain in dirnames; this can be used to 
> prune
>     the search, or to impose a specific order of visiting.  Modifying
>     dirnames when topdown is false is ineffective, since the directories in
>     dirnames have already been generated by the time dirnames itself is
>     generated.

Anticipating the next question :-) what Mike needs to do is

del dirnames[:] # must be in-situ deletion

not

dirnames = [] # wrong

before his continue statement

HTH
John


More information about the melbourne-pug mailing list