Problem with storing extracted values in SQLite - How to adress or index list of values for proper insertion into table.
The Regex works fine:
input logging data looks like:
0.0.0(06026104)
1.6.1(0.1501)(1011111000)
1.6.1*32(0.1446)(1010190800)
1.8.1(02484.825)
1.8.1*32(02449.574)
correct regex output:
06026104
0.1501
02484.796
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)
for item in mylist:
t = (item)
cursor.execute('INSERT INTO energielog(sernr) values (?)', [t])
cursor.execute('INSERT INTO energielog(peak) values (?)', [t])
cursor.execute('INSERT INTO energielog(kwh) values (?)', [t])
How can I achieve the proper line by line read into SQLite?
Now each line gets fed into table wrong: 06026104 is in line1 row1 and line2 row2 and line3 row3. Second value is only in line4 row1 and line5 row2 so forth..
For example, if I let
print t[0:3]
, the output is:
060
0.01
024
did it make rows out of it? How can I feed value 1 (06026104) into table row "sernr" and value2 (0.1501) into table row "peak" ..