首页 / 操作系统 / Linux / Python读取excel表格统计不同网段IP个数
import xlrd
file = xlrd.open_workbook("demo.xls") #打开表格
sheet1 = file.sheet_by_name(u"hhc") #获取表格
nrows = sheet1.nrows
dirt = {} #用于保存统计结果#统计不同
for i in range(0, nrows):
tempCell = sheet1.cell(i,0).value #0表示ip记录在第一列
temp = tempCell[:tempCell.rfind(".") ]
dirt.setdefault(temp, 0)
dirt[temp] += 1#打印统计结果
for name,address in dirt.items():
print ("%s : %s"%(name,address))使用表格 运行结果