[英]How to execute users input from info from mysql database using python
def choice_2():
number = int(input("Enter year: "))
if not conn:
connect()
query = "SELECT * from country IndepYear"
with conn:
cursor = conn.cursor()
cursor.execute(query, (number))
country = cursor.fetchall()
print()
in anaconda app giving me an error, Why?在 anaconda 应用程序中给我一个错误,为什么?
In this solution to your problem is putting your input in brackets (,) so the result would look something like this:在这个解决方案中,您的问题是将您的输入放在方括号 (,) 中,因此结果看起来像这样:
user_input = (raw_input("Enter year:"), )
Don't forget to put the comma,别忘了加逗号,
In full you have完整的你有
import MySQLdb
servername = "localhost";
username = "username";
password = "password";
conn = MySQLdb.connect(user=username,host=servername, passwd=password, db=db)
cursor = conn.cursor()
user_input = (raw_input("Enter year:"), )
query= ("SELECT * from country IndepYear")
cursor.execute(query,user_input)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.