Re: Hack with os.walk()

2005-02-12 Thread Michael Spencer
Tim Peters wrote: [Frans Englich] ... [snip] class HasPath: def __init__(self, path): self.path = path def __lt__(self, other): return self.path < other.path class Directory(HasPath): def __init__(self, path): HasPath.__init__(self, path) self.files = []

Re: Hack with os.walk()

2005-02-12 Thread Tim Peters
[Frans Englich] ... > My problem, AFAICT, with using os.walk() the usual way, is that in order to > construct the /hierarchial/ XML document, I need to be aware of the directory > depth, and a recursive function handles that nicely; os.walk() simply > concentrates on figuring out paths to all files

Re: Hack with os.walk()

2005-02-12 Thread Fernando Perez
Robert Kern wrote: > Fernando Perez wrote: > >> Perhaps this path.py could be considered for inclusion in the stdlib? I've >> only >> read the page linked above, so perhaps it can use some polishing. But it >> certainly looks like a big improvement over the scatterblast which the stdlib >> is o

Re: Hack with os.walk()

2005-02-12 Thread Robert Kern
Fernando Perez wrote: Perhaps this path.py could be considered for inclusion in the stdlib? I've only read the page linked above, so perhaps it can use some polishing. But it certainly looks like a big improvement over the scatterblast which the stdlib is on this particular topic. I'm pretty sure

Re: Hack with os.walk()

2005-02-12 Thread Fernando Perez
Michael Spencer wrote: > The path module by Jorendorff: http://www.jorendorff.com/articles/python/path/ > > wraps various os functions into an interface that can make this sort of thing > cleaner Wow, many thanks for the pointer. This has to be one of the single most useful small python modules

Re: Hack with os.walk()

2005-02-12 Thread Michael Spencer
Frans Englich wrote: Hello, Have a look at this recursive function: def walkDirectory( directory, element ): element = element.newChild( None, "directory", None ) # automatically appends to parent element.setProp( "name", os.path.basename(directory)) for root, dirs, files in os.walk(

Hack with os.walk()

2005-02-12 Thread Frans Englich
Hello, Have a look at this recursive function: def walkDirectory( directory, element ): element = element.newChild( None, "directory", None ) # automatically appends to parent element.setProp( "name", os.path.basename(directory)) for root, dirs, files in os.walk( directory ):