0
我有一个python字典,将列名从源表映射到目标表。Python字典映射到SQL查询字符串
词典:
tablemap_computer = {
'ComputerID' : 'computer_id',
'HostName' : 'host_name',
'Number' : 'number'
}
我需要动态地生成以下查询字符串,这样当新的列名对被添加到字典中会正确更新。
ComputerID=%(computer_id)s, HostName=%(host_name), Number=%(number)s
这样做的好方法是什么?
我有一个开始,但它是非常混乱,并在最后一个元素的末尾有一个额外的逗号。
queryStrInsert = ''
for tm_key, tm_val in tablemap_computer.items():
queryStrInsert += tm_key+'=%('+tm_val+')s,'