Apr-14-2019, 09:31 PM
Thanks for the help, but now it's not reading anything from the file. I also needed to fix the issue that the program would stop working if a file was entered with the wrong headings, and my solution worked, but for some reason, now that I have both of the pieces together, csv.DictReader doesn't seem to read anything. It's probably something stupid, but I can't figure out why it won't work anymore. Any more help? Thank you.
if file.endswith('.csv'): with open(file, 'r') as names: titles = csv.reader(names) titles = list(titles) titles = titles[0] if titles == ['Name', 'Surname']: toDB = [] reading = csv.DictReader(names) for row in reading: if (row['Name']).isalpha() and (row['Surname']).isalpha(): toDB.append((i['Name'], i['Surname'])) else: root = tk.Tk() error = tk.Label(root, text = "Error: invalid titles. Must be 'Name' and 'Surname'.") error.pack() root.after(5000, lambda: root.destroy()) root.mainloop() root = tk.Tk() root.geometry("0x0") dbChoice(root)