Saturday, March 08, 2008

cx_Oracle executemany() Example

cx_Oracle executemany() Example: "executemany() is that it takes a sequence of mappings, as its second argument, not a sequence of sequences. The first argument is the statement itself. More specifically, that means a list of dictionaries."

def convertSequenceToDict(list):
"""For each element in the sequence, creates a dictionary item equal
to the element and keyed by the position of the item in the list.
Thanks to Dick Wall.
Example:
>>> convertListToDict(("Matt", 1))
{'1': 'Matt', '2': 1}
"""
dict = {}
argList = range(1,len(list)+1)
for k,v in zip(argList, list): dict[str(k)] = v
return dict