os.path.walk arg

Tim Peters tim.one at comcast.net
Thu Mar 13 12:17:25 EST 2003


[Afanasiy]
> What is the purpose of arg in os.path.walk(path, visit, arg) ?

It's just something passed to every visit() call.  Passing None is fine.  So
is passing 42.  You can do something useful with it by passing a mutable
object, and writing your visit() function to mutate that object.  For
example, you can arrange to have your visit() function accumulate a list of
all .py files it found.  Or you can use it to pass in control information,
such as a list of file extensions you want to ignore.

IOW, there's no *specific* intended use.  It's a simple hook to let you pass
info into and out of your visit() function, if you want to.

BTW, like many frameworks in Python, figuring out how to use os.path.walk()
can be harder than just writing a simple loop to do the same thing directly.






More information about the Python-list mailing list