Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. import csv
  2. import mysql.connector
  3.  
  4. config = {
  5. 'user': 'root',
  6. 'password': 'dipals',
  7. 'host': 'localhost',
  8. 'database': 'naseef_csv',
  9. 'raise_on_warnings': True
  10. }
  11.  
  12. cnx = mysql.connector.connect(**config)
  13. cursor = cnx.cursor()
  14.  
  15. add_tax_query = "INSERT INTO tax_data (c1, c2, c3, c4) VALUES(%s, %s, %s, %s)"
  16.  
  17.  
  18. with open('TAX_ROLL_05_16_19.txt') as csv_file:
  19. csv_reader = csv.reader(csv_file, delimiter='\t')
  20. line_count = 0
  21. for row in csv_reader:
  22. #print (",".join(row))
  23. #print (row[0])
  24. #print (row[1])
  25. #print (len(row))
  26. cursor.execute(add_tax_query, (row[0], row[1], row[2], row[3]))
  27. cnx.commit()
  28.  
  29. cursor.close()
  30. cnx.close()
  31.  
  32. print ('done')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement