Using a list as a class parameter

qz_*_*_99 1 python oop class list

class Interface():
    def __init__(self, localIP, remoteIP, numHops, hops):
        self.localIP = localIP
        self.remoteIP = remoteIP
        self.numHops = numHops
        self.hops = []
Run Code Online (Sandbox Code Playgroud)

I want to create an instance like this:

hops, hopIps = stripRoute(ssh.run("traceroute -I " + str(dstHost.ip), hide=True))
host.interfaces.append(Interface(host.ip, dstHost.ip, hops, hopIps))
print(hops)
print(hopIps)
Run Code Online (Sandbox Code Playgroud)

From the print statements I can see that hopIps has a value and length 1 which is expected. However when I then query the new instance of Interface, only the numHops value was updated, hops remains empty.

Cor*_*mer 6

You passed a list into __init__ but never used it

class Interface():
    def __init__(self, localIP, remoteIP, numHops, hops):
        self.localIP = localIP
        self.remoteIP = remoteIP
        self.numHops = numHops
        self.hops = []
Run Code Online (Sandbox Code Playgroud)

Just assign your list to the member

class Interface():
    def __init__(self, localIP, remoteIP, numHops, hops):
        self.localIP = localIP
        self.remoteIP = remoteIP
        self.numHops = numHops
        self.hops = hops
Run Code Online (Sandbox Code Playgroud)