[Python-Dev] Coding guidelines for os.walk filter

Michael Urman murman at gmail.com
Wed Aug 31 04:21:52 CEST 2011


> for t in os.walk(somedir):
>    t[1][:]=set(t[1])-{'.svn','tmp'}
>    ... do something
>
> This is a very clever hack but... it relies on internal implementation
> of os.walk....

This doesn't appear to be an internal implementation detail; this is
documented behavior.
http://docs.python.org/dev/library/os.html#os.walk shows a similar example:

    for root, dirs, files in os.walk('python/Lib/email'):
        # ...
        dirs.remove('CVS')  # don't visit CVS directories

-- 
Michael Urman


More information about the Python-Dev mailing list