help needed on generator

Mark McEahern marklists at mceahern.com
Wed May 8 22:38:17 EDT 2002


[Gonçalo Rodrigues]

> I've coded this generator to traverse a directory tree.

1.  First of all, check this out:

  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/105873

2.  In this section of your code, you are calling the generator:

>         if predicate(dirname):
>             dirtree(os.path.join(root, dirname), predicate)

But with a generator, you need to iterate over it.  Consider replacing the
second line there with this:

            for x in dirtree(os.path.join(root, dirname), predicate):
                yield x

> When I feed "C:" to the sucker (run as script) only "C:" gets printed.
> Can anyone point out to me what I am doing wrong?

3.  Why C: and not r'C:\'?  C: is the current directory on C:, true?  Maybe
that's what you want, eh?

I hope this helps.

Cheers,

// mark






More information about the Python-list mailing list