python中sql语句的占位符


报错信息:"File"/usr/lib/pymodules/python2.6/MySQLdb/cursors.py", line 151, inexecute query = query % db.literal(args)

TypeError: %d format: a number is required, not str"

 

MySQLdb的字符串格式化不是标准的python的字符串格式化,

应当一直使用%s用于字符串格式化

 

python中无论整数,字符串占位符都为  %s,且不需加单引号

sql="insert into myauth_perm(permname, permurl, permdemo, parentid) values(%s, %s, %s, %s)"
cur.execute(sql,[html_permname, html_permurl, html_permdemo,html_parentid])

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM