So I'm working on an assignment, and I've come to a obstacle I can't seem to overcome. I'm essentially designing a rudimentary Library System. I have to read in from a file the books, librarians, and patrons and parse them in to lists then to objects. I've gotten the parsing to lists part down and have them ready to be used to create objects. Here's where I have the issue when I try to read from the lists I get and IndexError, and I can't figure out how to fix it.
My list where the first item is the ISBN, then the Title, then Author, then it repeats, i.e. ['123','The Scarlet Letter', 'Nathaniel Hawthorne']
self._bookList = ['123', 'The Scarlet Letter', 'Nathaniel Hawthorne', '456', 'Lord of the Rings', 'JRR Tolkien', '789', 'A Tale of Two Cities', 'Charles Dickens', '10112', 'Wuthering Heghts', 'Emily Bronte', '131415', 'Jane Eyre', 'Charlotte Bronte', '161718', 'Pride and Predudice', 'Jane Austin']
Snippet where I have the problem. I've tried using len(self._bookList)-1, +1, +2, +3. Nothing seems to work.
def _addToCollection(self):
i = 0
while i < len(self._bookList):
ISBN = []
ISBN.append(self._bookList[i])
title = []
title.append(self._bookList[i+1])
author = []
author.append(self._bookList[i+2])
#print(self._bookList[i],self._bookList[i+1],self._bookList[i+2])
BookCollection.addBook(self,str(ISBN[i]),str(title[i]),str(author[i]))
i += 1