When you talk about the names of your rows you confuse me. Do you mean you have a table named energielog having three columns named sernr, peak and kwh?
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159
Your example has only enough data for inserting one row.
#!/usr/bin/env python
#python 2
import re
import sqlite3
conn = sqlite3.connect('example')
c = conn.cursor()
mylist = []
with open("usage.log") as fp:
for line in fp:
match = re.match(r'(0\.0\.0|1\.6\.1|1\.8\.1)\(([0-9\.]+)', line)
if not match: continue
version, value = match.groups()
mylist.append(value)
#Execute the cursor
c.execute('INSERT INTO energielog (sernr, peak, kwh) VALUES (?, ?, ?)', mylist)
# Save (commit) the changes
conn.commit()
#Retrieve and display all rows from your table
c.execute('select * from energielog order by sernr')
for row in c:
print row
# Close the cursor
c.close()
Running the above gives the following output:
(u'06026104', u'0.1501', u'02484.825')
Note: I don't specify a value for ROWID because I assume it will autoincrement.
d5e5
Practically a Posting Shark
810 posts since Sep 2009
Reputation Points: 159
Solved Threads: 159