Advertisement
joseleeph

Untitled

Mar 31st, 2021
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. #import cs50
  2. #import csv, argv
  3.  
  4. #online edit
  5. #import cs50
  6. #added
  7. #from cs50 import SQL
  8. import cs50
  9. import csv
  10. from sys import argv
  11.  
  12. studb = cs50.SQL("sqlite:///students.db")
  13. with open("characters.csv", "r") as students:
  14. reader = csv.DictReader(students, delimiter = ",")
  15. nmesplt = ""
  16. frstnme = ""
  17. mdlnme = ""
  18. lastnme = ""
  19.  
  20. for row in reader:
  21. index = 0
  22. nmesplt = row['name'].split(" ")
  23.  
  24. if len(nmesplt) == 3:
  25. frstnme = nmesplt[0]
  26. mdlenme = nmesplt[1]
  27. lastnme = nmesplt[2]
  28.  
  29. studb.execute("INSERT INTO students(first, middle, last, house, birth) VALUES(?, ?, ?, ?, ?)", frstnme, mdlenme, lastnme, row['house'], row['birth'])
  30. if len(nmesplt) == 2:
  31. frstnme = nmesplt[0]
  32. mdlenme = ""
  33. lastnme = nmesplt[1]
  34.  
  35.  
  36. studb.execute("INSERT INTO students(first, middle, last, house, birth) VALUES(?, ?, ?, ?, ?)", frstnme, mdlenme, lastnme, row['house'], int(row['birth']))
  37.  
  38. index += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement