Advertisement
joseleeph

Untitled

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