在MySQL插入语句中使用Python变量 [英] Using Python variables in MySQL insert statement
本文介绍了在MySQL插入语句中使用Python变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经尝试了一段时间,并且已经上网查找并且无法弄清楚.
I've been trying for a while now and have look online and can't figure it out.
变量是数字
和动物
sql = ("INSERT INTO favourite (number, info) VALUES (numbers, animals )")
cursor.execute(*sql)
conn.comit()
推荐答案
使用:
sql=("INSERT INTO favourite (number, info) VALUES ({},{})".format(numbers,animals))
根据将来的参考使用格式总是好的.检查 https://docs.python.org/release/3.1.5/library/stdtypes.html#old-string-formatting-operations
Its always good to use format as per future references. Check https://docs.python.org/release/3.1.5/library/stdtypes.html#old-string-formatting-operations
这篇关于在MySQL插入语句中使用Python变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文