Python Forum

Full Version: what could i do with my file tree list generator?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
a while back we talked about walking a file tree and i found the function to do that in the Python library had a strange order to it, but the order i wanted was depth first, equivalent to doing a sort of the whole list with "/" being sorted lowest. i ended up writing a generator to do it and yield the whole tree one path at a time, in standard sorted order. i wrote a little command to use it and show that it really works. recently, i added support to accept a key function reference for custom sorting. if that key is given, it sorts the names it gets from each directory, passing that key to the sorted function each time it is called. i wrote a test command for that using a key function that sorts runs of digits as the numeric value, i.e. "foo64bar" will be before "foo1728bar".

what i want to ask is, what kinds of programs/scripts could i write that make use of this generator? i would be especially interested in something that could not be done very well with anything but a generator.
i am thinking of making an alternate version or an option keyword to do breadth-first ordering. i was doing a manual breadth-first search for something, today, and thought there might be an advantage to having such a tool based on such an iterator.
i posted the source over in snippets.
should i add a file name filter, such as re, to my generator, or should that stay outside? is there any example code showing how to stack a generator and a filter (my term for a generator that repeats an iterator given to it and yields selected results from it).