[Tutor] sqlite3 lists to database conversion/ using python variables in sqlite3

Kent Johnson kent37 at tds.net
Wed Nov 19 14:39:37 CET 2008

On Wed, Nov 19, 2008 at 7:21 AM, amit sethi <amit.pureenergy at gmail.com> wrote:
> Thanks Kent , very useful reply but the thing is i actually want to use this
> in a program that stores ID3 tags and they are broken more usually than not
> .. so I actually don't know what keys/attributes i would be sending can I
> send attribute list as a parameter?
> I believe this is more elegant.
>>>>c.execute("insert into Music_tags (%s) values (%s)") %(audio_keys,
>>>> audio_values)

Again, the parentheses are in the wrong place for this to work. It should be
c.execute("insert into Music_tags (%s) values (%s)" % (audio_keys,

but I don't recommend this. It's OK to supply the field names by
string interpolation, it's the values that should be supplied as a
separate sequence.

> however i have to use this instead
>>>>c.execute("insert into Music_tags (File,Artist,Album,Title,date,Genre)
>>>> values(?,?,?,?,?,?)"\
> ,(iter,audio['Artist'].pop() or None,audio['Album'].pop() or
> None,audio['Title'].pop() or None,audio['date'].pop() or
> None,audio['Genre'].pop() or None))
> Notice the audio['Artist'].pop() or None
> None has to added to account for a case where their are no tags.

I don't understand this requirement. If 'Artist' is not present in the
audio dict, then audio['Artist'] will raise an exception. So I think
there is already a value for Artist. It may be an empty string rather
than None, so this would change it to None. I don't know why you need
the pop() either.


PS Please use Reply All to reply to the list.

More information about the Tutor mailing list