Python Forum
Validating information from .csv file before executemany
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validating information from .csv file before executemany
#3
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)
Reply


Messages In This Thread
RE: Validating information from .csv file before executemany - by mzmingle - Apr-14-2019, 09:31 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] formula for validating monetary values? kakos_k9 1 842 Dec-17-2022, 09:28 PM
Last Post: woooee
  Command error - cursor.executemany(comandoSQL,valoresInserir) TecInfo 2 1,479 Nov-18-2022, 01:57 PM
Last Post: TecInfo
  getting information from a text file Nickd12 8 3,355 Nov-17-2020, 01:29 AM
Last Post: bowlofred
  MERGE SQL in oracle executemany kaladin 0 3,205 Oct-12-2020, 11:48 AM
Last Post: kaladin
  Validating user input WJSwan 2 2,214 Jul-06-2020, 07:21 AM
Last Post: menator01
  Text file information retreval cel 4 2,618 Jun-04-2020, 02:21 AM
Last Post: cel
  Validating the functionality of the application rpalakodety 1 1,831 Dec-30-2019, 07:58 PM
Last Post: ndc85430
  Extracting information from a file lokhtar 6 3,056 Dec-09-2019, 09:44 PM
Last Post: snippsat
  Errors to get information of multiple files into a single file csv Clnprof 3 2,693 Aug-30-2019, 04:59 PM
Last Post: ThomasL
  Using executemany to import the data Sandy7771989 1 2,760 Jun-11-2019, 07:45 AM
Last Post: Sandy7771989

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020