[docs] [issue12970] os.walk() consider some symlinks as dirs instead of non-dirs

Akira Li report at bugs.python.org
Mon Jul 28 16:16:39 CEST 2014


Akira Li added the comment:

I've updated os.walk() documentation to mention that *dirnames* list
includes symlinks to directories.

To imitate the other two cases:

- treat the symlinks as files:

    for dirpath, dirnames, files in os.walk(top):
        dirs = []
        for name in dirnames:
            (files if islink(join(dirpath, name)) else dirs).append(name)
        dirnames = dirs

- don't include in either of the lists:

    for dirpath, dirnames, files in os.walk(top):
        dirnames[:] = [name for name in dirnames
                       if not islink(join(dirpath, name))]

where islink = os.path.islink and join = os.path.join.

I've uploaded the documentation patch. Please, review.

----------
nosy: +akira
Added file: http://bugs.python.org/file36138/docs-walk-issue12970.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue12970>
_______________________________________


More information about the docs mailing list