我有两个类,在第一个类中,我创建第二个类的实例,并执行第二个类的方法,即启动进程的方法。
t1.py
test = "t1"
def executeBase():
base = baseNode.BaseNode()
baseNode.BaseNode.executeBase(test, base) #error
和baseNode.py
class BaseNode():
def __init__(self):
self.eui48 = "01:00:00:00:00:00"
self.port = 7919
def executeBase(self, test, base):
#I execute here a process
我在(#error)行中收到错误。
File "/testbench/testbenchPython/test/t1.py", line 20, in executeBase
baseNode.BaseNode.executeBase(test, base)
TypeError: executeBase() missing 1 required positional argument: 'base'
这不可能吗?如果是,那是什么问题,我该如何解决? 我尝试以不同的方式传递参数,但是没有找到解决方案。
非常感谢您!
答案 0 :(得分:0)
在这种情况下
def executeBase():
base = baseNode.BaseNode()
baseNode.BaseNode.executeBase(test, base) #error
我正在猜测executeBase()函数正在寻找自我!代替baseNode.BaseNode.executeBase(test, base) #error
这行可能有效base.executeBase(test,base)
答案 1 :(得分:0)
您应该在实例上致电executeBase
。尝试以下操作:
def executeBase():
base = baseNode.BaseNode()
base.executeBase(test, base)