Last active
June 6, 2019 13:42
-
-
Save dheles/6355c8a668b976f1a1b16871d2cb5777 to your computer and use it in GitHub Desktop.
example python script for inserting values into a single-column sqlite db
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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