Adding data to SqlLite3 database, but only one value with Python

Life is hard, when you are learning Python and you see things that are making no sense the way they run. After writing about adding data to SqlLite3 with Python, today I have tried to do the same, but for one column only. In general, this should be a piece of cake – just remove the second column and enjoy. However, it was not that easy, as far as I somehow realized that Python was allowing to add only 1 letter of the request.

Thus, the following piece of code:

was returning the nice error below, stating obviously that the JavaScript input was considered to be 10 bindings, 1 for each word:

Where was the problem. After too much debugging (more than I would be ever willing to admit), I have found out the problem was in the way the tuple was passed. E.g., if you want to pass a list of tuples, inform python it is a list of tuples, otherwise it takes it for something else. Thus, this is the correct way to do it (the comma is important):

And it nicely works. The whole code, including creating and table in the database is here:

Enjoy it!

Tagged with: , , ,