I'm working on a scrabblecheat program
Following some examples I have the following code below which uses SQLite for a simple database to store my words.
However it tells me I can't recreate the database table.
How do I write in a check for if there is already a table named spwords, then skip trying to create it?
The error:
(<class 'sqlite3.OperationalError'>, OperationalError('table spwords already exists',), None) The Code:
def load_db(data_list): # create database/connection string/table conn = sqlite.connect("sowpods.db") #cursor = conn.cursor() # create a table tb_create = """CREATE TABLE spwords (sp_word text, word_len int, word_alpha text, word_score int) """ conn.execute(tb_create) # <- error happens here conn.commit() # Fill the table conn.executemany("insert into spwords(sp_word, word_len, word_alpha, word_score) values (?,?,?,?)", data_list) conn.commit() # Print the table contents for row in conn.execute("select sp_word, word_len, word_alpha, word_score from spwords"): print (row) if conn: conn.close()