You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python调用类方法find_action时报参数数量不匹配错误的原因是什么?

报错原因

Python类的实例方法被实例对象调用时,self参数会由解释器自动传入,不需要开发者手动显式传递。
你定义的find_action方法本身仅声明了2个参数:第一个是自动传入的实例本身self,第二个是业务参数search_term。
当你写self.find_action(self, bit)时,实际给方法传递了3个参数:自动传入的第一个self + 你手动填写的第二个self + 第三个bit,和方法定义的参数数量不匹配,因此抛出对应的类型错误。

修复方案

只需要删除check_action_free方法中调用find_action时手动传递的self参数即可,修改后的代码行为:

if self.find_action(bit) is not None:

修改后的完整check_action_free方法如下:

def check_action_free(self, params):
    bits = re.split(";", params)
    for bit in bits:
        if self.find_action(bit) is not None:
            return False
    return True

内容的提问来源于stack exchange,提问作者Tel Monks

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.23 15:36:03