Skip to content

Instantly share code, notes, and snippets.

@jamiesun
Created September 21, 2012 10:30
Show Gist options
  • Select an option

  • Save jamiesun/3760813 to your computer and use it in GitHub Desktop.

Select an option

Save jamiesun/3760813 to your computer and use it in GitHub Desktop.
gensql
#coding:utf-8
def gensql(table,dicts):
with open("%s.table.sql"%table,'w') as buff:
for sqlobj in dicts:
ks,vs = '',''
for k,v in sqlobj.items():
ks += '%s,'%k
vs += '\'%s\','%v
sql = "insert into %s (%s) values(%s);"%(table,ks[:-1],vs[:-1])
print >> buff,sql
if __name__ == "__main__":
datas = dict(username="demo",password="demo",email="[email protected]")
gensql("user",(datas,))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment