Reading .csv in Python - error list index out of range -


i trying display information stored in .csv file via tkinter. csv file called questionnaire.csv , in same directory questionnairedisplayresults.py file used display information stored. when execute questionnairedisplayresults.py,

i following error:

traceback (most recent call last):   file "z:\group project\questionnairedisplayresults.py", line 69, in <module>     main()   file "z:\group project\questionnairedisplayresults.py", line 64, in main     app = displayresults(root)   file "z:\group project\questionnairedisplayresults.py", line 14, in __init__     self.retrieveresponse(scrollbar)   file "z:\group project\questionnairedisplayresults.py", line 32, in retrieveresponse     firstname = row[0] indexerror: list index out of range 

the information in .csv file:

as,as,buisness information systems iuoioiu,iuooiiuooiu,buisness information systems joe,blogg,buisness information systems 

the code:

from tkinter import * import csv  class displayresults(frame): # gui setup     def __init__(self, master):     # initialise questionnaire class          frame.__init__(self, master)         scrollbar = scrollbar(master)         scrollbar.pack(side=right, fill=y)                self.pack()         self.retrieveresponse(scrollbar)         self.centre_window()      def retrieveresponse(self,scrollbar):          self.txtdisplay = text(self, height=14, width=100, bg='#cdd1cd', yscrollcommand=scrollbar.set)      # initialise text box         scrollbar.config(command=self.txtdisplay.yview)         self.txtdisplay.tag_configure('title', font=('ms', 14, 'bold'), underline=1)    # initialise title text style         self.txtdisplay.tag_configure('data', font=('ms', 12))      # initialise details text style          tab_results = ("\t" + "\t" + "\t")          # initialise variable style tabulation           self.txtdisplay.insert(end,"\t" + "forename" + tab_results + "surname"                                 + tab_results + "suggested degree" + "\n", 'title')     # insert title text           open('questionnaire.csv', 'rb') f:             reader = csv.reader(f)             row in reader:                 firstname = row[0]                 lastname = row[1]                 degree = row[2]                  self.txtdisplay.insert(end,"\t" + firstname + tab_results + lastname                                         + tab_results + degree + "\n", 'data')  # insert details text box          self.txtdisplay['state'] = disabled         self.txtdisplay.pack()       def centre_window(self):          width = 750         height = 225          swidth = self.master.winfo_screenwidth()         sheight = self.master.winfo_screenheight()          x = (swidth - width)/2         y = (sheight - height)/2         self.master.geometry('%dx%d+%d+%d' % (width, height, x, y))     def main():     # main     root = toplevel()     root.minsize(750, 225)     root.maxsize(750, 225)     root.title("questionnaire results")     app = displayresults(root)     root.mainloop()   if __name__ == '__main__':     main() 


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -