I was testing the code out and ended up running "python import.py characters.csv" multiple times. Now when I go into sqlite3 and print out the data it's repeated itself 3 times over, once for every time I ran the import command.
How do I delete the repeated data from the database?
from sys import argv import cs50 import csv if len(argv) != 2: print('Usage: python import.py [NAME OF CSV FILE]') exit(1) db = cs50.SQL("sqlite:///students.db") with open(argv[-1], "r") as characters: reader = csv.DictReader(characters) for row in reader: currentname = row['name'].split() first, middle, last = currentname, currentname if len(currentname) == 3 else None, currentname[-1] house = row['house'] birth = row['birth'] # if len(currentname) == 3: # first, middle, last = currentname # else: # first, last = currentname # middle = None db.execute("INSERT INTO students (first, middle, last, house, birth) VALUES(?, ?, ?, ?, ?)", first, middle, last, house, birth) print("Rows Inserted")