help needed on generator
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Thu May 9 08:11:45 EDT 2002
On Wed, 8 May 2002 21:38:17 -0500, "Mark McEahern"
<marklists at mceahern.com> wrote:
>[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 did feed "C:\\" but it got trimmed when writing the post.
>
>I hope this helps.
Yes. Now that the error was pointed *it is obvious*.
>
>Cheers,
>
>// mark
Thanx to all that answered,
Gonçalo Rodrigues
More information about the Python-list
mailing list