如果我有这样的文本文件:
FastEthernet3/1
ip address 0.0.0.0
enable portfast
FastEthernet3/2
ip address 0.0.0.0
enable portfast
FastEthernet3/3
ip address 0.0.0.0
FastEthernet3/4
ip address 0.0.0.0
我想打印出没有启用portfast的接口。我如何在python中打印这个?
我有以下代码:
import os
import sys
root = "path to text file like the example above"
os.chdir(root)
current2 = os.getcwd()
print ("CWD = ", current2,"\n")
file = sys.argv[1]
f = open(file)
contents = f.read()
f.close()
print ("Number of GigabitEthernet:",contents.count("interface GigabitEthernet"))
print ("Number of FastEthernet:",contents.count("FastEthernet"))
x = open(file)
string1 = "enable portfast"
for line in x.readlines():
if line.startswith(string1)
print (line)
filehandle.close()
所以我可以找到启用 portfast 的行并打印它,但我希望它打印更多行,所以我知道女巫接口启用了 portfast。