I have made a object called Protocol that takes in a port and protocol name. This object is then stored in an array. My question is how do i access my object in the array? Im coming from mostly doing Java and I can't quite figure it out. I keep getting error 'int' object has no attribute getPort.
Protocol.py Object/Model
class Protocol:
def __init__(self, protocolName, port):
self.protocolName = protocolName
self.port = port
def setPort(self, port):
self.port = port
def setProtocol(self,protocolName):
self.protocolName = protocolName
def getPort(self):
return self.port
def getProtocol(self):
return self.protocolName
JSONSlicer.py Where function is
from Model.Protocol import Protocol
from Model.Service import Service
class JSONSlicers:
def protocolSeperator(self,protocols,num):
protocolsFound = [] # Protocol port # odds, Protocol name # evens
i=0
for p in protocols:
for sub in range(0,len(p.split('/')) - 1):
# protocol = Protocol(p.split('/')[sub])
fPort = p.split('/')[sub]
sub+=1
fProto = p.split('/')[sub]
#protocol = Protocol(p.split('/')[sub])
protocol = Protocol(fPort,fProto)
protocolsFound.append(protocol)
print(protocolsFound[0].getPort()) # Trying to print attribute of object here
return protocolsFound
protocolsFound = [num]puts a number in the array, instead of a protocol. This gives you the error when you're trying to callgetPorton this numberlower_case_with_underscoresstyle (see PEP 8).