我想访问if
语句之外的列表,python中是否有静态函数?
列表为switch1Flow
,switch2Flow
和switch3Flow
:
这是代码
def startingNode(self, destID, message, counter):
pack = self.pac.packet(self.name, destID, message)
if counter == "0":
nextHop = self.controller.selectSwitch(self.name)
print "Switch", self.name, "contacts controller"
nextHop.receivePacket(pack)
switch1Flow = [nextHop.name] //list1
print switch1Flow
nextHop1 = self.controller.selectSwitch(nextHop.name)
print "Switch", nextHop.name, "contacts controller"
nextHop1.receivePacket(pack)
nextHop2 = self.controller.selectSwitch(nextHop1.name)
print "Switch",nextHop1.name,"contacts controller"
nextHop2.receivePacket(pack)
switch2Flow = [self.name, nextHop1.name] // list2
print switch2Flow
switch3Flow = [nextHop.name, nextHop2.name] // list3
print switch3Flow
elif counter == "1":
if 's2' in switch1Flow:
print "forwarding to s2"
if 's1' in switch2Flow and 's3' in switch2Flow:
print "forwarding to s3"
if 's2' in switch3Flow and 's4' in switch3Flow:
print "forwarding to s4"
print "message reched s4"
我想访问switch1Flow,switch2Flow和switch3Flow以便在elif中访问。你能建议我怎么做?
答案 0 :(得分:1)
定义clone
条件之外的开关变量你应该没问题:
finalize