title: Getting "TypeError: 'NoneType' object is not subscriptable" with pattern.search
body: <p>I was working on a python program made to write out the IP addresses from an error log file. I got it coded but whenever I try it on my error log I get a</p>
  <blockquote>
  <p>TypeError: 'NoneType' object is not subscriptable</p>
  </blockquote>
  <p>I wrote the code under this in case anyone wants to see what I did specifically. If anyone knows my mistake that would be great.</p>
  <pre><code>import re
  
  with open(r'C:\Users\Admin\Desktop/Test error file.txt') as fh:
     file = fh.readlines()
  
  pattern = re.compile(r'(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})')
  
  list=[]
  
  for line in file:
      lst.append(pattern.search(line)[0])
  
  print(list)
  </code></pre>