passing object methods to os.path.walk ?
Fredrik Lundh
fredrik at pythonware.com
Wed Feb 14 06:07:33 EST 2001
John Schmitt wrote:
> I did something like this:
>
> class foo:
> def __init__(self):
> os.path.walk( self.stuff, self.slurp, self.otherstuff )
> def slurp(self):
> #some code here
does "something like" mean:
def slurp(arg, top, names):
# correct if slurp is a function, wrong if it's a method
or
def slurp(self, arg, top, names):
# wrong if slurp is a function, correct if it's a method
> and I got a 'TypeError: too many arguments; expected 3, got 4' message from
> ntpath.py line 264 which reads
>
> func( arg, top, names )
os.path.walk calls the callback with three arguments. If you use a
bound instance method as callback, Python inserts the instance (self)
first in the argument list.
Cheers /F
More information about the Python-list
mailing list