MCPcopy Create free account
hub / github.com/ActiveState/code / Dict2Str

Function Dict2Str

recipes/Python/577605_AuGenerate_Simple_SQL/recipe-577605.py:4–16  ·  view source on GitHub ↗
(dictin,joiner=',')

Source from the content-addressed store, hash-verified

2
3# To Generate string
4def Dict2Str(dictin,joiner=','):
5 # make dict to str, with the format key='value'
6 #tmpstr=''
7 tmplist=[]
8 for k,v in dictin.items():
9 # if v is list, so, generate
10 # "k in (v[0], v[1], ...)"
11 if isinstance(v, (list, tuple)):
12 tmp = str(k)+' in ('+ ','.join(map(lambda x:'\''+str(x)+'\'',v)) +') '
13 else:
14 tmp = str(k)+'='+'\''+str(v)+'\''
15 tmplist.append(' '+tmp+' ')
16 return joiner.join(tmplist)
17def gen_update(table,dicts,conddicts):
18 # conddicts maybe the Condition, in sql, where key='value' or key in (value)
19 # dicts are the values to update

Callers 3

gen_updateFunction · 0.85
gen_selectFunction · 0.85
recipe-577605.pyFile · 0.85

Calls 5

strFunction · 0.85
mapFunction · 0.85
itemsMethod · 0.45
joinMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected