My aim is to take the data from 3 different CSV file and create a nested dictionary, I realize my error, but I fail to fix it.
Shall I create 3 different methods for each file to iterate the data and then create the nested dictionary, or it is something else that I have to do?
Code:
class STproject:
def __init__(self,app): #1
self.mlb=LabelFrame(app, text='Movie Recommendation Engine')
self.mlb.grid()
self.lframe3=LabelFrame(self.mlb,text="Movies/Users",background='purple')
self.lframe3.grid(row=0,column=1)
self.framebutton=Frame(self.mlb,background='pink',height=50,width=50)
self.framebutton.grid(row=0,column=0)
self.buttonsnlabels()
def buttonsnlabels(self):
self.ratingbutton=Button(self.framebutton,text='Upload movies',command=lambda :self.file1())
self.ratingbutton.grid()
self.ratingbutton=Button(self.framebutton,text='Upload ratings',command=lambda :self.file2())
self.ratingbutton.grid()
self.ratingbutton=Button(self.framebutton,text='Upload links',command=lambda :self.file3())
self.ratingbutton.grid()
def file1(self):
umovies=tkFileDialog.askopenfilename()
f=open(umovies)
self.csv_file1 = csv.reader(f)
self.dictionary()
def file2(self):
uratings=tkFileDialog.askopenfilename()
f=open(uratings)
self.csv_file2 = csv.reader(f)
self.dictionary()
def file3(self):
links=tkFileDialog.askopenfilename()
f=open(links)
self.csv_file3 = csv.reader(f)
self.dictionary()
def dictionary(self):
for line1,line2,line3 in zip(self.csv_file1,self.csv_file2,self.csv_file3):
dict={}
dict[line1]={[line2]:[line3]}
root=Tk()
root.title()
application=STproject(root)
root.mainloop()
and this is the error given:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\Lib\lib-tk\Tkinter.py", line 1547, in __call__
return self.func(*args)
File "C:/Users/Umer Selmani/Desktop/voluntarily/Voluntiraly.py", line 825, in <lambda>
self.ratingbutton=Button(self.framebutton,text='Upload movies',command=lambda :self.file1())
File "C:/Users/Umer Selmani/Desktop/voluntarily/Voluntiraly.py", line 836, in file1
self.dictionary()
File "C:/Users/Umer Selmani/Desktop/voluntarily/Voluntiraly.py", line 858, in dictionary
for line1,line2,line3 in zip(self.csv_file1,self.csv_file2,self.csv_file3):
AttributeError: STproject instance has no attribute 'csv_file2'