I'm getting a weird error on some of my scripts. These worked like last week with the same code.
My code:
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))
And I am getting the error:
File "Vtst-linux.py", line 46, in <module>
print("This is lowest mask: {}".format(lwmask))
NameError: name 'lwmask' is not defined
I am getting this error on Linux Ubuntu Python versions 3.4.1 and 3.4.0 but not Windows on with the same Python versions. I have tried this on virtual environments on the Linux server and just running it from the install path with the same results. The input file is basically a bunch of IP networks in CIDR notation.
Any help is appreciated, I am baffled by this and I have tried changing the variable name and other things and it hasn't helped.
forloop where you definelwmaskwont be executed. Are you sure that you are using a non-empty file as input? Doesprint(lwmask)produce output on linux?