The problem is that for the current line
in current_ip.txt
, the string eth0:
is not found. Because of this, your if-statement returns False
.
if 'eth0:' in line:
inet_line = ip_file.next()
_time = time.asctime()
inet_string = inet_line[9:(inet_line.index('/'))]
If eth0:
is found in line
, inet_line
is defined, otherwise it will not be defined and Python jumps to the next code block which is where the exception is raised.
text = 'The IP address is: %s' % inet_string