python - 如何纠正 TypeError:execute() 需要 2 到 4 个位置参数,但给出了 5 个?
问题描述
我真的在这里挣扎..所以立即帮助将不胜感激。明天必须提交一个项目。如果这个问题被重复,请把答案的链接发给我。
if user_input==2:
number=int(input("Enter number of tickets you want to book-"))
for b in range(0,number):
passengername=input("Enter name of passenger-")
starting_station=input("Enter name of station from where passenger will board train-")
destination=input("Enter name of station passenger wishes to reach-")
print("Ticket Booked!")
mydb=mysql.connector.connect(host="localhost",user="root",passwd="",database="railways")
mycursor=mydb.cursor()
mycursor.execute("select train_no from route_fare where from_station=%s",(starting_station,), " and to_station=%s",(destination,))
for w in mycursor:
train_number_p=w
输出:
Enter number of tickets you want to book-1
Enter name of passenger-Ollie
Enter name of station from where passenger will board train-Jaipur Railway Station
Enter name of station passenger wishes to reach-Churu Railway Station
Ticket Booked!
Traceback (most recent call last):
File "<pyshell#9>", line 14, in <module>
mycursor.execute("select train_no from route_fare where from_station=%s",(starting_station,), " and to_station=%s",(destination,))
TypeError: execute() takes from 2 to 4 positional arguments but 5 were given
解决方案
推荐阅读
- jmeter - 如何在加速和减速期间忽略测试结果
- javascript - 在 div 滚动时或之后立即检测鼠标位置
- flask - 如何使用 javascript 从烧瓶数据库中获取数据?
- android - 如何防止缓存或垃圾文件清除后从 SD 卡中删除视频资产..?
- ios - Swift 阻止字符串连接结果中的 Optional("") 或 nil | 从对象创建查询字符串
- javascript - Webpack 函数触发两次
- python - 在 Pandas 中返回列表的聚合函数导致 ValueError:必须生成聚合值
- c# - 使用 log4net 时,我收到一条消息,指出当前上下文中不存在 XmlConfigurator
- javascript - JavaScript 中的随机数学游戏
- java - Flutter 支持 Kotlin 的优势