Hi,
I would like to know why, Idle is telling me that the IP is
not defined, here is my error msg from Python Idle:
And here is my code:
I would like to know why, Idle is telling me that the IP is
not defined, here is my error msg from Python Idle:
Code:
Traceback (most recent call last): File "E:/Charlie Python/11 Octo 2007/test5.txt", line 62, in <module> print 'loss = ' + loss + ip NameError: name 'ip' is not defined
And here is my code:
Code:
while not action: pingaling =os.popen("ping %s" %(ipAddress),"r") results = pingaling.read() print results for line in results: f=open('c:/tmp/workfile.txt', 'a+') f.write(line) f.close() for line in open("c:/tmp/workfile.txt"): s = 0 e = 0 loss_num = 0 # Initialize it if line.startswith("Ping statistics for"): ip=line.split()[-1][:-1] if line.find("(")!=-1: s=line.index("(") e=line.index(")") loss=line[s+1:e].replace("loss","") #------------------------------------------------------ print 'loss = ' + loss + ip loss_num = loss.strip() # remove spaces if any loss_num = loss_num.strip('%') # remove the % sign from loss print 'number = ' + loss_num try: loss_num = float(loss_num) # change it into a number if loss_num >= 2 : output_line = loss + ',' + "'" + ip + "'" + "\n" s=open('c:/tmp/myprimarylogs.txt', 'a+') #s=open('c:/tmp/primaryip.cvs', 'a+') s.write(output_line) #s.write(line+"\n") s.close() except: loss_num = '' print ('-----------------') print ('Please wait') print ('-----------------') # waiting time.sleep(1)
Comment