Python SQLite Regex ExecuteMany

57 Views Asked by At

Thanks in advance for your help.

I am in python using regex and bucket up the patterns in text. I then stored it in a list, and called upon that list when inserting values into a table using SQLite. However, I am getting a 'str' object has no attribute 'executemany.' The following code should work (as it does for a tuple of 2) and insert my data in, but it gives me an error.

searc_h = re.compile(r'([A-Z]{4}|[A-Z]{3})\s([\d]{4})\s-\s[A-Z]{1}\s\((\d\.\d)')
find_all = list(re.findall(searc_h, texter))

find_all_fin = []
for (a,b,c) in find_all:
    ap = (int(b), str(a), float(c))
    find_all_fin.append(ap)


c.executemany('INSERT INTO Takes VALUES (?, ?, ?)', find_all_fin)
conn.commit()

Here is the error enter image description here

Any help or advice would be greatly appreicated.

1

There are 1 best solutions below

0
On

You are reusing the variable c in two different places, one to store the database connection and another to store the Regex result in the for loop block. Disambiguate them and your code would do fine.