I see unboundlocalerror at random times. Could you please point me how to fix this?
def find_switch_and_port_cis(wwn):
with open('zones_list.txt') as fin:
for line in islice(dropwhile(lambda L: wwn not in L, fin), 1, 15, 1):
if 'connected interface' in line:
interface = re.findall(':(\S+)', line)
elif 'switch name' in line:
switch_name = re.findall(':(\S+)', line)
print(wwn, ' is connected to interface:' , interface[0], ' on switch:', switch_name[0])
find_switch_and_port_cis(wwn)
The code gives the expect output:
50:01:43:80:01:1b:42:f6 is connected to interface: fc2/17 on switch: c3-cs9513-02
After few runs but after few runs it throws:
UnboundLocalError: local variable 'interface' referenced before assignment