An easy way to create a table (and seed some data) if it doesn’t exist using Python and sqlite3.
1234567891011121314151617
importsqlite3defmain():conn=sqlite3.connect('data.db')conn.row_factory=sqlite3.Rowcursor=conn.cursor()try:cursor.execute('select * from prefs')exceptsqlite3.OperationalError:print'Table does not exist. Creating...'cursor.execute('create table prefs (key text, value text)')cursor.execute('insert into prefs(key, value) values (?, ?)',('testing','123'))conn.commit()print'Finished creating table.'cursor.execute("select value from prefs where key = 'testing'")row=cursor.fetchone()printrow['value']# prints '123'