Problem with a for loop and a list

Terry Reedy tjreedy at udel.edu
Wed Jul 2 04:27:15 EDT 2008



Alexnb wrote:
> I am not sure what is going on here. Here is the code that is being run:
> 
> def getWords(self):
>         self.n=0
>         for entry in self.listBuffer:
>             self.wordList[self.n] = entry.get()

And what does self.wordList begin as?  If {}, then the assignemt is 
invalid.  Perhaps you want self.wordList.append(entry.get())

>         self.n=self.n+1

Is this supposed to be incremented once per entry or once per 
getWords()?  If the former, you would overwrite previous assignment (if 
it worked) for every item except the last.




More information about the Python-list mailing list