title: Python - reading data from file with variable attributes and line lengths
body: <p>I'm trying to find the best way to parse through a file in Python and create a list of namedtuples, with each tuple representing a single data entity and its attributes. The data looks something like this:</p>
  
  <pre><code>UI: T020  
  STY: Acquired Abnormality  
  ABR: acab   
  STN: A1.2.2.2  
  DEF: An abnormal structure, or one that is abnormal in size or location, found   
  in or deriving from a previously normal structure.  Acquired abnormalities are  
  distinguished from diseases even though they may result in pathological   
  functioning (e.g., "hernias incarcerate").   
  HL: {isa} Anatomical Abnormality
  
  UI: T145   
  RL: exhibits   
  ABR: EX   
  RIN: exhibited_by   
  RTN: R3.3.2   
  DEF: Shows or demonstrates.   
  HL: {isa} performs   
  STL: [Animal|Behavior]; [Group|Behavior]   
  
  UI: etc...
  </code></pre>
  
  <p>While several attributes are shared (eg UI), some are not (eg STY). However, I could hardcode an exhaustive list of necessary.<br>
  Since each grouping is separated by an empty line, I used split so I can process each chunk of data individually:</p>
  
  <pre><code>input = file.read().split("\n\n")
  for chunk in input:
       process(chunk)
  </code></pre>
  
  <p>I've seen some approaches use string find/splice, itertools.groupby, and even regexes. I was thinking of doing a regex of '[A-Z]*:' to find where the headers are, but I'm not sure how to approach pulling out multiple lines afterwards until another header is reached (such as the multilined data following DEF in the first example entity).  </p>
  
  <p>I appreciate any suggestions.</p>