python execute传参,Python Execute()恰好接受2个参数(给定3个)

I am trying to insert into the SQLite DataBase values with this code:

con.Execute('''UPDATE tblPlayers SET p_Level = ? WHERE p_Username= ? ''', (PlayerLevel,PlayerUsername))

this is the Execute function:

def Execute(self,SQL):

self.__connection.execute(SQL)

self.__connection.comit()

and i am getting this error:

con.Execute('''UPDATE tblPlayers SET p_Level = ? WHERE p_Username= ?

''', (PlayerLevel,PlayerUsername)) TypeError: Execute() takes exactly

2 arguments (3 given)

解决方案

Your Execute() method takes only two arguments, self and SQL. The self argument is supplied by Python to bound methods, so there is only room for the SQL argument:

def Execute(self,SQL):

but you called the bound method with an additional argument, not just the one SQL argument:

con.Execute('''UPDATE tblPlayers SET p_Level = ? WHERE p_Username= ? ''',

(PlayerLevel,PlayerUsername))

The tuple value passed in, together with the auto-inserted self argument and the SQL argument makes three.

If you want to support SQL parameters, you'll need to accept those parameters:

def Execute(self, SQL, params=()):

self.__connection.execute(SQL, params)

self.__connection.commit()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值