os.path.walk arg
Erik Max Francis
max at alcyone.com
Thu Mar 13 22:41:46 EST 2003
Tim Peters wrote:
> [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.
This is, by the way, a pretty standard mechanism used in APIs that
support callbacks; you give a callback, and an object/pointer/reference
that will be sent to the callback by the caller, so that one can create
a context for the callback. (I know Tim knows this; this is for
Afanasiy's benefit.)
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ If I had known, I would have become a watchmaker.
\__/ Albert Einstein
Bosskey.net / http://www.bosskey.net/
A personal guide to online multiplayer first person shooters.
More information about the Python-list
mailing list