小编qz_*_*_99的帖子

Using a list as a class parameter

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.

python oop class list

1
推荐指数
1
解决办法
51
查看次数

标签 统计

class ×1

list ×1

oop ×1

python ×1