因此,这段代码的基本目标是报告一组设备上的哪些端口正在被利用
代码如下:
`$` file_name = input('Enter File Name: ') + str('.csv')
total_ports = 500
my_reader = csv.reader(open(file_name))
ctr = 0
for total_reserved in my_reader:
if total_reserved[2] == 'Reserved':
ctr += 1
print(ctr, 'out of ', total_ports, 'PLS ports are reserved')
my_reader = csv.reader(open(file_name))
ctr_pls0 = 0
for pls0 in my_reader:
if pls0[0] == 'L1 switches/L1 Switch 10G PLS0.BLLAB/Blade01' and total_reserved[2] == 'Reserved':
ctr_pls0 += 1
print(ctr_pls0, 'of these', ctr, 'are pls0 ports') `$`
这给了我以下输出
Enter File Name: 31.05.2018
175 out of 500 PLS ports are reserved
0 of these 175 are pls0 ports
Process finished with exit code 0
0 of these 175 are pls0 ports
这就是问题所在,此行应该为我提供根据.csv文件显示为'L1 switches/L1 Switch 10G PLS.BLLAB/Blade01'
和的端口数量
你知道这是什么吗
谢谢
在第二个循环中,应该使用
pls0[2]
,而不是total_reserved[2]
total_reserved
包含第一个循环中文件的最后一行但根本没有理由有两个循环,只需在第一个循环中增加两个变量
相关问题 更多 >
编程相关推荐