How about using **
(keyword argument unpacking) ?
insert_client = db.insert('clients', **dict)
BTW, don't use dict
as a variable name. It shadows builtin function dict
:
Question
dict(16)
['zone'] => str(3) "S/Z"
['name'] => str(20) "John user"
['country'] => str(3) "AGO"
['date1'] => str(10) "2012-04-23"
['date2'] => str(10) "1970-06-24"
....
def save(self):
insert_client = db.insert('clients', zone = dict.get('zone'), ...)
The only way that I know is, with a basic insert, and then iterate the dictionary to make N updates for N items in dict.
for key, val in dictionary.iteritems():
update_client = db.update('clients', key = val)
Any idea to make the insert more nice to work? Or should i use the basic insert and then complete the client profile with updates?
PS: the keys of python dict are the column name of database,
Solution
How about using **
(keyword argument unpacking) ?
insert_client = db.insert('clients', **dict)
BTW, don't use dict
as a variable name. It shadows builtin function dict
: