Question: I am running this code and getting error as : In Python:Traceback (most recent call last): File C:UserssanjiOneDriveDesktopPythonweek3Testing.py, line 18, in lst.append(pattern.search(line)[0]) TypeError: 'NoneType' object
I am running this code and getting error as :
In Python:Traceback (most recent call last): File "C:\Users\sanji\OneDrive\Desktop\Python\week3\Testing.py", line 18, in
CODE:
import re # opening and reading the file with open(r'C:\Users\sanji\OneDrive\Desktop\Python\week3\error_log.txt') as fh: fstring = fh.readlines() # decalring the regex pattern for IP addresses pattern = re.compile(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})') # initializing the list object lst=[] # extracting the IP addresses for line in fstring: lst.append(pattern.search(line)[0]) #search searchItem = pattern.search(line) if searchItem: item_array.append(searchItem[0]) # displaying the extracted IP adresses print(lst
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
