Guido van Rossum wrote: > >However, I can see other uses for looping over a sequence using a >generator and telling the generator something interesting about each >of the sequence's items, e.g. whether they are green, or should be >printed, or which dollar value they represent if any (to make up a >non-Boolean example). > >Anyway, "continue EXPR" was born as I was thinking of a way to do this >kind of thing in Python, since I didn't want to give up return as a >way of breaking out of a loop (or several!) and returning from a >function. > >But I'm the first to admit that the use case is still very much >hypothetical -- unlike that for g.next(EXPR) and VAR = yield. > > > 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. Joachim
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