title: Open CSV file and writing each row to new, dynamically named CSV file
body: <p>I have a csv file with, say, 50 rows of data, and I would like to split it into separate csv files for each row, which includes first row (header) and the the relevant row.</p>
  
  <p>E.g.
  file 1 contains: row1, row2,
  file 2 contains: row1, row3,
  file 3 contains: row1, row4</p>
  
  <p>And so on.</p>
  
  <p>Currently working with:</p>
  
  <pre><code>import csv
  
  counter = 1
  
  with open('mock_data.csv', 'r', newline='') as csvfile:
      reader = csv.reader(csvfile)
      for row in reader:
          filename = "file_%s" % str(counter)
          with open(filename, 'w') as csvfile_out:
              writer = csv.writer(csvfile_out)
              writer.writerow(row)
              counter = counter + 1
  </code></pre>
  
  <p>I'm currently getting 'csvfile_out' not defined.</p>
  
  <p>a) Am I even approaching this correctly
  b) Any ideas why csvfile_out isn't being defined?</p>