On Fri, 2005-06-17 at 13:53, Joachim Koenig-Baltes wrote: [...] > My use case for this is a directory tree walking generator that > yields all the files including the directories in a depth first manner. > If a directory satisfies a condition (determined by the caller) the > generator shall not descend into it. > > Something like: > > DONOTDESCEND=1 > for path in mywalk("/usr/src"): > if os.path.isdir(path) and os.path.basename(path) == "CVS": > continue DONOTDESCEND > # do something with path > > Of course there are different solutions to this problem with callbacks > or filters but i like this one as the most elegant. I have implemented almost exactly this use-case using the standard Python generators, and shudder at the complexity something like this would introduce. For me, the right solution would be to either write your own generator that "wraps" the other generator and filters it, or just make the generator with additional (default value) parameters that support the DONOTDECEND filtering. FWIW, my usecase is a directory comparison generator that walks two directorys producing tuples of corresponding files. It optionally will not decend directories in either tree that do not have a corresponding directory in the other tree. See; http://minkirri.apana.org.au/~abo/projects/utils/ -- Donovan Baarda <abo at minkirri.apana.org.au>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4