In [26]:
filename = "mat_data.sqlite"
Then, create a connection to the database. If it already exists, throw an exception so that you don't overwrite it.
In [27]:
import sqlite3
conn = sqlite3.connect(filename)
Once you have a Connection, you can create a Cursor object.
In [28]:
c = conn.cursor()
Create a table
In [29]:
c.execute('''CREATE TABLE clay (elem integer, d real, k_d real, s real)''')
Out[29]:
Insert a row of data for each element. This is FAKE data... for now.
In [30]:
elements = range(1,120)
for elem in elements :
d = elem*10.**(-6)
k_d = elem/200.
s = elem*2.
str_to_execute = "{0},{1},{2},{3}".format(elem,d,k_d,s)
c.execute("INSERT INTO clay VALUES ("+str_to_execute+")")
Save the changes and close the connection.
In [31]:
conn.commit()
conn.close()
test it
In [45]:
conn = sqlite3.connect(filename)
c = conn.cursor()
all = c.execute('''SELECT * FROM clay WHERE elem=2''')
print all.fetchone()
conn.close()
In [ ]: