[Tutor] os.path.walk

Alan Gauld alan.gauld at freenet.co.uk
Tue Aug 22 18:00:23 CEST 2006

> What has got me worried is that the function called by os.path.walk 
> must be a method of the class.
> Now this means it will have something like this as a def:
> def func_called_by_walk(self, arg, directory, names):
> Will this work with os.path.walk with that definition?

No, but you can wrap it in a lambda that calls the method:

lambda x,y,z: self.func_called_by_walk(x,y,z)

But have you looked at os.walk?
It is a little easier to use for most things IMHO.
No need to pass a function in for a start.

Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list