def insert_sql(*args, **kw):
for k in kw:
SQL_INSERT = "insert into nostray(%s) values('%s')" % (k, kw[k])
return SQL_INSERT
sql = insert_sql(userid="ka")比如传入userid=“a”到里面就是insert into nostray(userid) values("a")但是传入userid="a", username="b"就不是 insert into nostray(userid, username) values("a", "b")这样的话怎么写?谢谢
1 回答
ruibin
TA贡献358条经验 获得超213个赞
# -*- coding: UTF-8 -*-
def insert_sql(**kw):
keys = []
values = []
for k in kw:
keys.append(k)
values.append(kw[k])
SQL_INSERT = "insert into nostray%s values%s" % (tuple(keys),tuple(values))
return SQL_INSERT
# return SQL_INSERT
sql = insert_sql(userid="a", username="b", age='20')
print sql
添加回答
举报
0/150
提交
取消