我的一些脚本出现了一个奇怪的错误。它们的工作原理和上周一样。在
我的代码:import ipaddress
import csv
from csv import DictReader, DictWriter
import operator
import time
import os
import datetime
from datetime import datetime
cnt=1
FMT='%a %b %d %H:%M:%S %Y'
start_time=str(time.strftime("%c", time.localtime()))
forpth=r'/home/path/Geo_Assigned'
forfiles=[os.path.join(forpth, fname) for fname in os.listdir(forpth)if fname.startswith('DC')]
forlat=max(forfiles, key=os.path.getmtime)
mskcmlst=['255.255.255.254', '255.255.255.252', '255.255.255.248', '255.255.255.240', '255.255.255.224', '255.255.255.192', '255.255.255.128', '255.255.255.0', '255.255.254.0', '255.255.252.0', '255.255.248.0', '255.255.240.0', '255.255.224.0', '255.255.192.0', '255.255.128.0', '255.255.0.0', '255.254.0.0', '255.252.0.0', '255.248.0.0', '255.240.0.0', '255.224.0.0', '255.192.0.0', '255.128.0.0', '255.0.0.0']
alphlst=[]
WaitList=[]
cmpmask=ipaddress.ip_address('255.255.255.254')
msk32=ipaddress.ip_address('255.255.255.255')
n=0
with open(forlat, newline='') as fin:
read = DictReader(fin)
for line in read:
line['CIDR']=ipaddress.ip_network(line['CIDR'])
line['Mask']=line['CIDR'].netmask
lwmask=str(line['Mask'])
alphlst.append(line)
print(lwmask)
print("This is lowest mask: {}".format(lwmask))
endnum=mskcmlst.index(lwmask)+1
print("This is endnum {}".format(endnum))
我得到了一个错误:
^{pr2}$
我在LinuxUbuntuPython版本3.4.1和3.4.0上遇到了这个错误,但是在同一个Python版本的Windows上没有。我已经在Linux服务器上的虚拟环境中尝试过这个方法,并从安装路径运行它,结果是一样的。输入文件基本上是一组以CIDR表示的IP网络。在
任何帮助都是感激的,我对此感到困惑,我尝试改变变量名和其他事情,但没有帮助。在