title: How do I fix this list index out of range error?
body: <p>I'm trying to go through a txt file to pull out certain numbers, store them in a list, and then use the numbers to pull out strings stored in the same file. My code works on some of my files, but I'm suddenly getting a list index out of range error.</p>
  <p>Here is an example of the portion of the text file im trying to get out</p>
  <pre><code>                     /note=&quot;tRNA-Arg2&quot;
       tRNA            5573494..5573567
                       /locus_tag=&quot;Tery_R0035&quot;
                       /product=&quot;tRNA-Arg&quot;
  </code></pre>
  <p>or</p>
  <pre><code>     tRNA            complement(5630800..5630872)
                       /locus_tag=&quot;Tery_R0036&quot;
                       /product=&quot;tRNA-His&quot;
  </code></pre>
  <p>I'm trying to get the numbers that are written after tRNA.</p>
  <p>Here's my code to extract the numbers into a list:</p>
  <pre><code>def extract_numbers(line):
      #empty list
      numbers = []
      #creates a buffer (temporary space)
      digits = &quot;&quot;
      #for character in the line
      for c in line:
          #if its a digit
          if c.isdigit():
              #add character to the buffer
              digits += c
          #if it isnt a number
          else:
              #if there is something in the buffer (ie its not 0)
              if len(digits) &gt; 0:
                  #add the buffer to the numbers list
                  numbers.append(digits)
                  #empty again
                  digits = &quot;&quot;
      #to make sure the last number is added to the list
      if len(digits) &gt; 0:
          numbers.append(digits)
      return numbers
  </code></pre>
  <p>and to use the last function to write this over the file itself</p>
  <pre><code>def extract_tRNA(path):
      with io.open(path, mode=&quot;r&quot;, encoding=&quot;utf-8&quot;) as file:
          genome = file.readlines()
          start_stop = []
          for line in genome:
              if &quot;tRNA&quot; in line[0:21]:
                  numbers = extract_numbers(line[21:])
                  start_stop.append((int(numbers[0]), int(numbers[1])))
          return start_stop
  </code></pre>
  <p>then, I run it with this:</p>
  <pre><code>work_dir = &quot;/Users/...&quot;
  for path in glob.glob(os.path.join(work_dir, &quot;*.gbff&quot;)):
  
      sequences = extract_seq(path)
      tRNA_loc = extract_tRNA(path)
      extract_genes(path, tRNA_loc, sequences)
      print(path)
  </code></pre>
  <p>Is it my file or code? I'm also not sure if there is an easier way to do the same thing?</p>
  <p>Thanks for any help!</p>
  <p>UPDATE trying regex:</p>
  <pre><code>work_dir = &quot;where my files are&quot;
  for path in glob.glob(os.path.join(work_dir, &quot;*.gbff&quot;)):
      with io.open(path, mode=&quot;r&quot;, encoding=&quot;utf-8&quot;) as file:
          genome = file.readlines()
          for line in genome:
              if &quot;tRNA&quot; in line[0:21]:
                  p = re.compile('\d+')  # \d means digit and + means one or more
                  m = p.findall(line)
          print(m)
  </code></pre>