title: Parsing Text Files with Python 3, Regex and Random Numbers
body: <p>Here is the input text file I am working with: <a href="https://gist.github.com/TestAcc7777/5983147" rel="nofollow">https://gist.github.com/TestAcc7777/5983147</a></p>
  
  <p>In the text file, each line after the initial few contains 'CORE X', where X is a number from 1 to 64. Some of the lines containing 'CORE X' also contain either 'V3' or 'V4. </p>
  
  <p>For each value of X, I want to output the lines containing 'CORE X' and that also only contain one of 'V3' or 'V4' - which one to is be decided using a random number generator.</p>
  
  <p>I've written the following in Python 3, and incorporated some regex, to write all lines containing 'CORE X' except those containing the rejected 'V' fragments:</p>
  
  <pre><code>import re
  import random
  
  tri = open(input("Input File: "))
  tro = open(input("Output File: "),'w')
  
  for line in tri.readline():
      for i in [1,65,1]:
          if random.random()&gt;0.5:
              q = 4
          else:
              q = 3
          if re.search(r'CORE\s'+str(i), line):
              if re.search(r'V', line):
                  if re.search(r'V'+str(q), line):
                      tro.write(line)
              else:
                  tro.write(line)
  </code></pre>
  
  <p>When I run the program however, it seems to finish rather quickly and the output file is empty. I still rather inexperienced with Python and programming in general, so any help in getting my program to help will be greatly appreciated.</p>