title: Pythonic multiple text tables within one text file to CSV conversion
body: <p>I'm still learning python and was wondering what a pythonic way (aka less is more) of coding the following problem.</p>
  
  <p>Due to the wonders of 1990s technology, a text file is dumped to the server everyday with csv tables in it. That's right - one text file with <em>two</em> csv tables.</p>
  
  <p>Goal: To parse out the csv tables and make them into two different csv files.</p>
  
  <p>File looks like this:</p>
  
  <pre><code>start of file
  blah blah
  blah blah
  blah blah
  
  +--------
  ,tbl1, tbl1,
  +--------
  ,data, data,
  ,data, data,
  .....
  ,data,data
  +--------
  blah blah
  blah blah
  blah blah
  +--------
  ,tbl2, tb2,
  +--------
  ,data, data,
  ,data, data,
  ....
  ,data, data,
  blah blah
  blah blah
  </code></pre>
  
  <p><strong>Issue: Table 1 is varying in length.</strong></p>
  
  <p>I need to be able to extract table 1 no matter what the length of the table is and make it a CSV file.</p>
  
  <p>I have</p>
  
  <pre><code>def lp_to_csv(in_file_name, out_filename):
  #open the input &amp; output files.
  inputfile = open(in_file_name, 'rb')
  csv_file = out_filename
  out_csvfile = open(csv_file, 'wb')
  
  #read in the correct lines
  my_text = inputfile.readlines()[117:-8]
  del my_text[1]
  for row in my_text:
      #cycle through to find the end
      if row[0] != ",":
          print "excludeded: " + row
  
  #convert to csv using "," as delimiter
  in_txt = csv.reader(my_text, delimiter = ',')
  #hook csv writer to output file
  out_csv = csv.writer(out_csvfile)
  #write the data
  out_csv.writerows(in_txt)
  
  #close up
  inputfile.close()
  out_csvfile.close()
  </code></pre>
  
  <p>but that code only makes 1 csv file and it includes the second block of 'blah blah'.</p>
  
  <p>I think I know how to make it two csv files (create a subroutine that creates a csv file with the my_text object, but how do I cut out the blah blah and how do i trigger when to chop it into 2 tables?</p>
  
  <p>Can anyone direct me for a nice pythonic way?</p>
  
  <p>ANSWERED:
  Very similar to below answer:
  I created a subroutine that created a list of where the delimiter <code>+-----</code> was. Since it's always in groups of three, First, Heading Row, End.</p>
  
  <p>Then I chunk into groups of three the list.</p>
  
  <p>Then activate the table making code on each group of three.</p>
  
  <p>Pretty handy so far &amp; stateless which is nice.</p>