[Python-Dev] Withdrawn PEP 288 and thoughts on PEP 342
Raymond Hettinger
python at rcn.com
Sat Jun 18 06:58:06 CEST 2005
[Joachim Koenig-Baltes]
> > 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.
[Donovan Baarda]
> 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/
Thank both of you for the excellent posts. This is exactly kind of
feedback and analysis that will show whether continue EXPR is worth it.
Raymond
More information about the Python-Dev
mailing list