[Tutor] Pouring a list into a dictionary then into database

Allen aschmidt at fredericksburg.com
Mon Sep 29 20:32:11 EDT 2003


Hi Danny! Thanks for the quick response!

> Ah!  As of Python 2.3, there's another concise way of saying this:

...but how about for 2.1.3? This resides on a Zope box and so using the 
Python that installed with it.



> One way to do this is to move the crsr.execute() within the loop body
> itself:
> 
> ###
> sql = "replace into tablename %s values (%s)"
> for k, v in map(None, headings, foundData):      ## we can use zip()
>     crsr.execute(sql, (k, v))
> ###

But for the way I am using REPLACE, I need to do the whole line at one time.



> you can also call the executemany() method to do this operation on your
> whole list of key/value pairs.  So you should be able to say:
> 
> ###
> sql = "replace into tablename %s values (%s)"
> crsr.executemany(zip(headings, foundData))
> ###

So where does the sql go??


Still confused. I will keep poking around. Thanks again!

> Good luck to you!
Thanks! I think I will need it!





More information about the Tutor mailing list