cmap = {'s0': [c0], 's1': [c1], 's2': [c1]}
class MultiSwitch(OVSSwitch):
"Custom Switch() subclass that connects to different controllers"
def start(self, controllers):
return OVSSwitch.start(self, cmap[self.name])
现在假设我有两个开关列表:
switchL1 = [s1, s2, s3]
switchL2 = [s4, s5]
我想用一个循环来实现这个映射,而不是一个一个地写,这样第一个列表中的开关将连接到一个控制器,第二个列表中的开关将映射到另一个控制器。
所以应该是这样的:
cmap = {'switchL1': [c0], 'switchL2': [c1]}
class MultiSwitch(OVSSwitch):
"Custom Switch() subclass that connects to different controllers"
def start(self, controllers):
return OVSSwitch.start(self, cmap[self.name])
我该怎么做?我试过这个密码:
cmap = {'%s': [c0] % (sw1) for sw1 in range(switches_L1), '%s': [c1] % (sw2) for sw2 in range(switches_L2)}
invalid syntax error