Overview#

Typical Usage#

It is recommended to use Walk as a context manager, otherwise make sure to call Walk.close() when you’re done iterating.

with Walk(".") as walk:
    for entry in walk:
        print(entry.path)

Error Handling#

Like os.walk(), errors are ignored by default. You must set an onerror function if you want to report the error or re-raise it to abort the walk.

def onerror(exc):
    print(exc)


with Walk(".", onerror=onerror) as walk:
    for entry in walk:
        print(entry)

Mutable Attributes#

All the arguments that can be passed to Walk can also be accessed as attributes on the instance. Mutations are only possible if iteration hasn’t yet started.

with Walk(".") as walk:
    walk.paths.append("/foo")
    walk.hidden = False
    for entry in walk:
        ...

Modifying attributes after iteration starts is an error:

with Walk(".") as walk:
    for entry in walk:
        walk.hidden = True
Traceback (most recent call last):
    ...
RuntimeError: This property is read-only once iteration has started