Skip to content

Instantly share code, notes, and snippets.

@dheles
Created June 5, 2019 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dheles/cfa493c77ac5a98ee64a16246db25a59 to your computer and use it in GitHub Desktop.
Save dheles/cfa493c77ac5a98ee64a16246db25a59 to your computer and use it in GitHub Desktop.
example python script inserting into a sqlite db
#!/usr/bin/env python
import sqlite3
def main():
conn = sqlite3.connect('example.db')
c = conn.cursor()
# Create table
c.execute('''CREATE TABLE example
(id integer, key text, value text)''')
# Larger example that inserts many records at a time
data = [(1, 'first', 'this'),
(2, 'then', 'that'),
(3, 'finally', 'the other')
]
c.executemany('INSERT INTO example VALUES (?,?,?)', data)
for row in c.execute('SELECT * FROM example ORDER BY id'):
print(row)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment