[Tutor] Request for help with os.walk() combining os.path.ismount() in Linux

Alan Gauld alan.gauld at btinternet.com
Thu Aug 20 18:57:37 CEST 2015


On 20/08/15 09:51, Srihari Vijayaraghavan wrote:

> In general I agree, but this is what the os.walk() document states:
> "... When topdown is True, the caller can modify the dirnames list
> in-place (perhaps using del or slice assignment)..."

That's true so far as the os.walk call goes.
That is, altering dirs does not have any nagative
impact on the subsequent iterations of os.walk.
So even if you delete items from dirs os.walk will
continue to iterate over those deleted directories
in subsequent calls to os.walk()

But altering dirs within the current iteration does affect
dirs within that iteration, just like any other collection.
So your for loop inside the os.walk loop is affected by the
deletions even if the outer os.walk loop is not.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list