|
From: Alexnb on 2 Jul 2008 04:04 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() self.n=self.n+1 print self.wordList This is the "listBuffer" that you see: self.listBuffer=[self.e1, self.e2, self.e3, self.e4, self.e5, self.e6, self.e7, self.e8, self.e9, self.e10, self.e11, self.e12, self.e13, self.e14] (side note, those are all tkinter entry widgets, and the get() function gets the text) this is the error the interpreter is giving me when I run it: self.getWords() File "C:/Documents and Settings/Alex/My Documents/PYTHON/DictionaryApp/The GUI.py", line 153, in getWords self.wordList[self.n] = entry.get() IndexError: list assignment index out of range I have no idea what "list assignment index out of range means?!?! -- View this message in context: http://www.nabble.com/Problem-with-a-for-loop-and-a-list-tp18232298p18232298.html Sent from the Python - python-list mailing list archive at Nabble.com.
From: A.T.Hofkamp on 2 Jul 2008 04:15 On 2008-07-02, Alexnb <alexnbryan(a)gmail.com> wrote: > I have no idea what "list assignment index out of range means?!?! You are assigning a value to a non-existing list element, as in >>> x = [1] >>> x[2] = 4 Traceback (most recent call last): File "<stdin>", line 1, in ? IndexError: list assignment index out of range Albert
From: Alexnb on 2 Jul 2008 04:21 well okay, so what can I do? A.T.Hofkamp-3 wrote: > > On 2008-07-02, Alexnb <alexnbryan(a)gmail.com> wrote: >> I have no idea what "list assignment index out of range means?!?! > > You are assigning a value to a non-existing list element, as in > >>>> x = [1] >>>> x[2] = 4 > Traceback (most recent call last): > File "<stdin>", line 1, in ? > IndexError: list assignment index out of range > > > Albert > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Problem-with-a-for-loop-and-a-list-tp18232298p18232528.html Sent from the Python - python-list mailing list archive at Nabble.com.
From: Terry Reedy on 2 Jul 2008 04:27 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.
From: Alexnb on 2 Jul 2008 04:31
Actually I tried that and had no sucsess, but I just figured it out. I set every value in wordList to 'None' and so even if all the entry fields aren't taken up, they go to '', so I can tell what is and what isn't taken up, and get the string of the ones that are taken up. Terry Reedy wrote: > > > > 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. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Problem-with-a-for-loop-and-a-list-tp18232298p18232688.html Sent from the Python - python-list mailing list archive at Nabble.com. |