Especialized generator

Terry Reedy tjreedy at udel.edu
Thu Mar 4 20:05:05 EST 2004


"Boogie El Aceitoso" <frr149 at telefonica.net> wrote in message
news:hltd409mao1mmlk6kn5rjk00i5342p8pk6 at 4ax.com...
> I want to write a generator that specializes on os.walk. It should yield
only
> certain kinds of files.
>
> What's the best way of doing this? How do you save the state on the base
> generator?

For those who didn't get the chaining idea (latter reply): something like

def boogie_walk(testarg, *walkargs):
   for item in os.walk(*walkargs):
        if <boogie_test using testarg, item>: yield item

I presume there is also ifilter() or something in itertools that will do
the same.

Terry J. Reedy








More information about the Python-list mailing list