Especialized generator

  • Thread starter Boogie El Aceitoso
  • Start date
B

Boogie El Aceitoso

Hi,

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?

TIA
 
M

Miki Tebeka

Hell Boogie,
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?
Using os.walk :)

HTH.
Miki
 
A

Aahz

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?

You don't. You write another generator that yields appropriate results
from calling os.walk(). Chaining generators is *wonderful*.
 
B

Boogie El Aceitoso

You don't. You write another generator that yields appropriate results
from calling os.walk(). Chaining generators is *wonderful*.

I think I got it. And yes, it IS wonderful. :)
 
T

Terry Reedy

Boogie El Aceitoso said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top