Re: Help me understand this iterator

2006-10-31 Thread LaundroMat
On Oct 31, 3:53 pm, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > LaundroMat wrote: > > That 'magic index' variable bugs me a little however. It gives me the > > same feeling as when I see hard-coded variables.what magic index? the > > variable named "index" is an argument to the > method it's used

Re: Help me understand this iterator

2006-10-31 Thread Fredrik Lundh
LaundroMat wrote: > That 'magic index' variable bugs me a little however. It gives me the > same feeling as when I see hard-coded variables. what magic index? the variable named "index" is an argument to the method it's used in. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help me understand this iterator

2006-10-31 Thread LaundroMat
Thanks all, those were some great explanations. It seems I have still still a long way for me to go before I grasp the intricacies of this language. That 'magic index' variable bugs me a little however. It gives me the same feeling as when I see hard-coded variables. I suppose the generator class

Re: Help me understand this iterator

2006-10-31 Thread LaundroMat
Ack, I get it now. It's not the variable's name ("index") that is hard-coded, it's just that the for...in... loop sends an argument by default. That's a lot more comforting. -- http://mail.python.org/mailman/listinfo/python-list

Re: Help me understand this iterator

2006-10-31 Thread Peter Otten
LaundroMat wrote: [me hitting send too soon] > Now, if I look at this script step by step, I don't understand: > - where the "while 1:"-loop is quitted. > class DirectoryWalker: > # a forward iterator that traverses a directory tree > > def __init__(self, directory): > self.sta

Re: Help me understand this iterator

2006-10-31 Thread Steven D'Aprano
On Tue, 31 Oct 2006 03:36:08 -0800, LaundroMat wrote: > Hi, > > I've found this script over at effbot > (http://effbot.org/librarybook/os-path.htm), and I can't get my head > around its inner workings. [snip code] > Now, if I look at this script step by step, I don't understand: > - what is be

Re: Help me understand this iterator

2006-10-31 Thread Peter Otten
LaundroMat wrote: > Hi, > > I've found this script over at effbot > (http://effbot.org/librarybook/os-path.htm), and I can't get my head > around its inner workings. Here's the script: > > import os > > class DirectoryWalker: > # a forward iterator that traverses a directory tree > > d

Re: Help me understand this iterator

2006-10-31 Thread Fredrik Lundh
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__

Help me understand this iterator

2006-10-31 Thread LaundroMat
Hi, I've found this script over at effbot (http://effbot.org/librarybook/os-path.htm), and I can't get my head around its inner workings. Here's the script: import os class DirectoryWalker: # a forward iterator that traverses a directory tree def __init__(self, directory): self.