A simple generator application

holger krekel pyth at devel.trillke.net
Sat Oct 12 13:44:54 EDT 2002


Doug Fort wrote:
> I've been looking for an excuse to actually use a generator. I need to put
> include guards on a bunch of C++ header files. So I started out to create
> a generator that does what os.path.walk does, with yield in place of the
> callback 'visitor' function.
> 
> It turned out to be not that simple; but Ive attached what I've got. I
> feel that this is worth cluttering up the group with because it's simple
> enough to grasp, but it actually does something.
> 
> Since this is a new way of thinking for me, I'm interested in how this
> task cold be done more cleanly.

It's already quite nice. 

But in 'fileWalker' i would try to avoid "duplicate" file-IO. 

First you are calling dirWalker which calls 'os.listdir'
and in each (yielded) result you call 'glob.glob' which
scans the directory again.

regards,

    holger




More information about the Python-list mailing list