daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Dec 7th, 2017 60 in 1 day
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. cur.execute('DROP TABLE IF EXISTS ways_nodes')
  2. conn.commit()
  3. cur.execute("CREATE TABLE ways_nodes (id , node_id, position)")
  4. conn.commit()
  5. with open('ways_nodes.csv','rb') as fin: # `__with` statement available in 2.5+
  6.     # csv.DictReader uses first line in file for column headings by default
  7.     dr = csv.DictReader(fin) # comma is default delimiter
  8.     to_db = [(i['id'].decode("utf_8"), i['node_id'].decode("utf_8"),i['position'].decode("utf_8")) for i in dr]
  9.  
  10. cur.executemany("INSERT INTO ways_nodes (id,node_id,position) VALUES (?, ?,?);", to_db)
  11. conn.commit()
RAW Paste Data
Top