“TypeError:缺少1个必需的位置参数”实例

2024-05-19 19:18:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个类,在第一个类中,我创建第二个类的一个实例,并执行第二个类的一个方法,一个启动进程的方法。在

t1.py型

test = "t1"

def executeBase():
    base = baseNode.BaseNode()
    baseNode.BaseNode.executeBase(test, base) #error

以及baseNode.py在

^{pr2}$

我在行中得到了错误。在

  File "/testbench/testbenchPython/test/t1.py", line 20, in executeBase
baseNode.BaseNode.executeBase(test, base)
TypeError: executeBase() missing 1 required positional argument: 'base'

这不可能吗?如果是,问题是什么?我如何纠正它? 我试过用不同的方法来传递论点,但没有找到解决办法。在

非常感谢!在


Tags: 实例方法pytestbase进程def错误
2条回答

您应该在实例。试试这个:

def executeBase():
    base = baseNode.BaseNode()
    base.executeBase(test, base)

在这种情况下

def executeBase(): base = baseNode.BaseNode() baseNode.BaseNode.executeBase(test, base) #error

我猜executeBase()func在找self!代替baseNode.BaseNode.executeBase(test, base) #error这一行可以base.executeBase(test,base)

相关问题 更多 >