gpt4 book ai didi

python - 类型错误:必须使用 Interface 实例作为第一个参数来调用未绑定(bind)方法 getInterfaceName()(什么也没有)

转载 作者:太空宇宙 更新时间:2023-11-03 15:00:14 24 4
gpt4 key购买 nike

类(class)单位: def init(self, _chassisId, _unitNo, _interface): self.chassisId = _chassisId self.unitNo = _unitNo self.interface = _interface

def getInterface(self):
return self.interface

@staticmethod
def parse(elem):
unitList = elem.find(UNIT+LIST)
chassisList = []
for unit in unitList.findall(UNIT):
try:
unitNumber = unit.find(UNIT_NUMBER).text
interface = unit.find(INTERFACE)
interface = ""
chassisIdElem = unit.find(CHASSIS_ID)
chassisId = ""
if chassisIdElem is not None:
chassisId = unit.find(CHASSIS_ID).text
elif unit.find(BURNED_IN_MAC) is not None:
chassisId = unit.find(BURNED_IN_MAC).text
chassisId = chassisId.replace(".", "").replace(":", "").upper()
chassis = Unit(chassisId, interface, unitNumber)
chassisList.append(chassis)
except Exception as e:
print "Unit details not found", e
return chassisList

def getChassisId(self):
return self.chassisId

def __str__(self):
str = "\n"
str += "\nUnit Details:- "
len = str.__len__();
str += "\n"
for i in range(1,len-1):
str += "-"
str += "\nUnit: " + self.unitNo
str += "\nChassis Id: " + self.chassisId
str += "\nInterfaces: " + self.interfaces
return str

def __add__(self, other):
return str(self) + other

def __radd__(self, other):
return other + str(self)

类接口(interface): def init(self, _linkState, _interfaceName): self.linkState = _linkState self.interfaceName = _interfaceName

@staticmethod
def parse(elem):
prefix = Device.getPrefix(elem.tag)
interfaceList = elem.find(INTERFACE + LIST)
interfaceNameTag = eval(prefix + "_INTERFACE_NAME")
linkStateTag = eval(prefix + "_LINK_STATE")
interfaces = []
for interface in interfaceList.findall(INTERFACE):
try:
interfaceName = interface.find(interfaceNameTag).text
linkStateElem = interface.find(LINK_STATE)
linkState = ""
if linkStateElem is not None:
linkState = interface.find(LINK_STATE).text
elif interface.find(LINE_PROTOCOL) is not None:
linkState = interface.find(LINE_PROTOCOL).text
interface = Interface(linkState, Name)
interfaces.append(interface)
except Exception as e:
print "Interface details not found", e
return interfaces

def getLinkState(self):
return self.linkState

def getInterfaceName(self):
return self.interfaceName

def __str__(self):
str = "\n"
str += "\nInterface Details:- "
len = str.__len__();
str += "\n"
for i in range(1,len-1):
str += "-"
str += "\nLink State: " + self.linkState
str += "\nInterface Name: " + self.interfaceName
return str

def __add__(self, other):
return str(self) + other

def __radd__(self, other):
return other + str(self)

最佳答案

您没有向我们展示导致错误的 getInterfaceName() 调用,这使得我们更难为您提供帮助。

但是,我猜调用看起来像这样:

something = Interface.getInterfaceName()

你不能那样做。您必须创建 Interface实例,然后调用其 .getInterfaceName() 方法:

myInterface = Interface()
something = myInterface.getInterfaceName()

关于python - 类型错误:必须使用 Interface 实例作为第一个参数来调用未绑定(bind)方法 getInterfaceName()(什么也没有),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45175113/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com