使用“ break”时输出不是预期的

时间:2019-12-02 20:37:36

标签: python logic break

输出不是预期的。我希望在“系统”目录下打印有关“系统”的所有差异,并在“接口”目录下打印与“接口”相关的所有差异。即使我有声明要抓住它,“ {...}”也不会打印。代码如下:

255

输出给出:

var r, g, b;
for(r = 0; r < 256; r++) {
    for(g = 0; g < 256; g++) {
        for(b = 0; b < 256; b++) {
            console.log(r + " " + g + " " + b);
        }
    }
}

预期输出:

import re
template_list = ['system','interfaces']
directory = '/templates/juniper/junos/vfirewall/'
diff = """[edit system name-server]
    8.8.8.8 { ... }
+   4.4.4.4;
[edit interfaces ge-0/0/0 unit 0 family inet]
+       address 10.20.30.10/24;
-       address 10.50.30.10/24;
[edit interfaces]
+   ge-0/0/1 {
+       unit 2 {
+           family inet {
+               address 10.50.80.10/24;
+           }
+       }
+   }""".splitlines()

for template in template_list:
 print("{}{}".format(directory,template))
 for line in diff:
   if(re.match(r'\[edit\s({})'.format(template),line)):
     print('{}'.format(line))
   elif(re.match(r'\{ \.\.\. \}',line)):
     print('{}'.format(line))
   elif(re.match(r'^\-',line)):
     print('{}'.format(line))
   elif(re.match(r'^\+',line)):
     print('{}'.format(line))
   elif(re.match(r'\[edit\s\w.+',line)):
     break

0 个答案:

没有答案