title: Python set output file is empty
body: <p>I am writing a Python script to read in a file, read through that file line by line and parse out data from that file to another text file via user command line argument. Right now, I am able to read the input file line by line and parse out the data via command line argument. However, the output file that I am trying to write to is empty(it does not content the data I want to parse out).</p>
  
  <p>temp.log contain: </p>
  
  <pre><code>06 May 19 03:40:35 3 abCodeClearTrap Error Clear Trap (agent: 12367a12, 
  chassis:12367a12, ErrIdText: ERROR ID TEXT, csssi: EXTIFG, clearedID: 
  0x089088394)
  06 May 19 03:44:35 3 abCodeErrorTrap Error Trap (agent: 12368a15, chassis: 
  12368a15, ErrIdText: Skip this item, csssi: SSRSSR, clearedID: 
  0x089088394)
  </code></pre>
  
  <p>My code so far:</p>
  
  <pre><code>import re, sys
  
  with open('temp.log') as f:
      lines = f.readlines()
  
  output_file = open ('output.txt', 'w')
  
  data = []
  for line in lines:
     date = re.match(r'\d{2} \w+ \d{2}', line).group()    
     time = line.split()[3]
     ids = line.split()[4]
     row = [date, time, ids]
  
     if 'agent' in sys.argv:
         try:
            agent = re.search(r'agent:\s(.*?),', line).group()
            row.append(agent)
        except:
            agent = 'agent:'
    if 'err' in sys.argv:
        try:
            errID = re.search(r'ErrIdText:\s(.*?),', line).group()
            row.append(errID)
        except:
            errID = 'ErrIdText:'
    if 'clear' in sys.argv:
        try:
            clear = re.search(r'clearedID:\s(.*?)\)', line).group()
            row.append(clear)
        except:
            clear = 'clearedID:'
  
    data.append(row)
    output_file.writelines(row)
  
    for row in data:
    print(row)
  
    output_file.close()
  </code></pre>
  
  <p>I am expecting to write the output to a file call "output.txt" but that file is not generated by the code.</p>
  
  <p>So the user will run the command line argument 
      python export.py date agent 
  And I expect the output.txt file will have the list of date and agent but it is empty</p>