Nov-09-2017, 08:55 PM
I'm a beginner so dont beat me up too much :) .I have a program where a user enters a product number into a field and clicks a search button, the program then opens a csv file (see below), looks for that product number and should then only display (by inserting that data into a treeview) the data relevant, stopping once blank rows occur - this indicates the end of the part information and the start next part.
Example of the csv is below (excuse the use of the error box)
Error:Product PartDesc Drawings Issues Documents
1-1841111-2 bad feeling Dwg1 Iss A c:\company\docs\tfpp\widget1.xls
Dwg2 Iss B c:\company\docs\tfpp\bob.pdf
Dwg25 Iss Z c:\company\docs\tfpp\itsatrap.pdf
1-1841111-4 tribble Dwg3 Iss C c:\company\docs\tfpp\wibble.xls
1-1841111-5 nothing Dwg4 Iss D c:\company\docs\tfpp\rocket.pdf
Dwg5 Iss E c:\company\docs\tfpp\dwg1.doc
Unfortunately when I run the code I can only get a single csv row to display and have not been able to work out how get subsequent rows, stopping at a blank row. I am however, not convinced that the below code although its displays a single line as expected is operating correctly.def search(self): if self.SOentry.get() != "": x = self.dwgtree.get_children() for item in x: self.dwgtree.delete(item) self.partdesc.delete(0,'end') with open("c:\python\projects\somedwgs.csv") as csvfile: reader = csv.DictReader(csvfile) for row in reader: result=(row['Product']) if self.SOentry.get() == result: descr=(row['PartDesc']) descDwg=(row['Drawings']) descIss=(row['Issues']) descDscr=(row['Documents']) self.partdesc.insert(0,descr) while True: #if row['PartDesc'] != "": if descDwg != "": self.dwgtree.insert("",'end',values=(descDwg,descIss,descDscr)) next(reader) break