Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

sqlite3 error in python

So i have made this simple program that stores data for an experiment. i wanted to use sqlite, so thats what i did. After assigning a file and setting things up, I wrote the following script:

def data_entry(extracted_data):
    c.execute('INSERT INTO data VALUES({}) '.format(', '.join(data for data in extracted_data)))

While running the program. I got *** syntax error *** with the following message:

c.execute('INSERT INTO data VALUES({}) '.format(', '.join(data for data in extracted_data)))
sqlite3.OperationalError: near ")": syntax error

any suggestions on why this occurred ?

[MOD: fixed ```python formatting -cf]

Hi

"But the thing is that i don't want to print , i want to execute the sqlite commands. Im going to run it any way and see what i get."

right, but by doing a print and posting the result here, we can see what .format(', '.join(data for data in extracted_data))) is producing; and I am pretty sure that once you look at the printed string , you may be able to figure out what went wrong, and correct accordingly.

1 Answer

Hello

I would do this to debug the problem

print('INSERT INTO data VALUES({}) '.format(', '.join(data for data in extracted_data)))

and look at the sql data and see if you can run the resulting SQL stand alone

But the thing is that i don't want to print , i want to execute the sqlite commands. Im going to run it any way and see what i get.