title: Parsing text event file in Python
body: <p>I have a large text file with Event data that I am trying to parse to a csv.  The structure looks like this:</p>
  
  <p>START <br>
  USER: a <br>
  TIME: 1000 <br>
  CLICKS: 1 <br>
  COMMAND A: 2 <br>
  COMMAND B: 1 <br>
  END <br>
  START <br>
  USER: b <br>
  TIME: 00 <br>
  CLICKS: 1 <br>
  COMMAND A: 2 <br>
  COMMAND B: 1 <br>
  COMMAND C: 1 <br>
  END <br></p>
  
  <p>The events are separated using the START and END tags and I am trying to parse it to create a csv file that has each event as a row, and the other attributes as columns, so in the example above, the columns would be USER, TIME, CLICKS, COMMAND A, COMMAND B, COMMAND C and the values for each would be the value after the :</p>
  
  <p>I know that this code will read an individual event: </p>
  
  <pre><code>with open('sampleIVTtxt.txt', 'r') as input_data:
  for line in input_data:
      if line.strip() == 'START REPORT':
  break
  for line in input_data:  
      if line.strip() == 'END':
  </code></pre>
  
  <p>Where I am stuck is how to parse the lines within the event block and store them as columns and values in a csv. I'm thinking for each line within the event block I need to parse out the column name using regex and then store those names in an array and use writerow(namesarray) to create the columns. But I'm not sure how to loop through the whole txt file and store subsequent event values in those columns.</p>
  
  <p>I am new to python, so any help would be appreciated. </p>