title: How to import a csv-file into a data array?
body: <p>I have a line of code in a script that imports data from a text file with lots of spaces between values into an array for use later.</p>
  
  <pre><code>textfile = open('file.txt')
  data = []
  for line in textfile:
      row_data = line.strip("\n").split()
      for i, item in enumerate(row_data):
          try:
              row_data[i] = float(item)
          except ValueError:
              pass
      data.append(row_data)
  </code></pre>
  
  <p>I need to change this from a text file to a csv file. I don't want to just change this text to split on commas (since some values can have commas if they're in quotes). Luckily I saw there is a csv library I can import that can handle this.</p>
  
  <pre><code>import csv
  with open('file.csv', 'rb') as csvfile:
      ???
  </code></pre>
  
  <p>How can I load the csv file into the data array?</p>
  
  <p>If it makes a difference, this is how the data will be used:</p>
  
  <pre><code>row = 0
  for row_data in (data):
      worksheet.write_row(row, 0, row_data)
      row += 1
  </code></pre>