Skip to content

Instantly share code, notes, and snippets.

@dheles
Last active June 6, 2019 13:42
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/6355c8a668b976f1a1b16871d2cb5777 to your computer and use it in GitHub Desktop.
Save dheles/6355c8a668b976f1a1b16871d2cb5777 to your computer and use it in GitHub Desktop.
example python script for inserting values into a single-column 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
(key text)''')
# Larger example that inserts many records at a time
data = ['first','then','finally']
c.executemany('INSERT INTO example(key) VALUES (?)', zip(data))
for row in c.execute('SELECT * FROM example ORDER BY key'):
print(row)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment