Re: Help me understand this iterator
- From: Fredrik Lundh <fredrik@xxxxxxxxxxxxxx>
- Date: Tue, 31 Oct 2006 12:58:28 +0100
LaundroMat wrote:
Now, if I look at this script step by step, I don't understand:
- what is being iterated over (what is being called by "file in
DirectoryWalker()"?);
as explained in the text above the script, this class emulates a sequence. it does this by implementing the __getindex__ method:
http://effbot.org/pyref/__getitem__
- where it gets the "index" value from;
from the call to __getitem__ done by the for-in loop.
- where the "while 1:"-loop is quitted.
the loop stops when the stack is empty, and pop raises an IndexError exception.
note that this is an old example; code written for newer versions of Python would probably use a recursing generator instead (see the source code for os.walk in the standard library for an example).
</F>
.
- References:
- Help me understand this iterator
- From: LaundroMat
- Help me understand this iterator
- Prev by Date: Re: How can I import a script with an arbitrary name ?
- Next by Date: Re: Where do nested functions live?
- Previous by thread: Re: Help me understand this iterator
- Next by thread: Re: Help me understand this iterator
- Index(es):