title: Parsing data from csv file to Google Spreadsheet with python
body: <p>I'm writing a python script to send data from a csv file to a Google Spreadsheet. I'm have a clear understanding of the basics need for this project, however I'm totally lost regarding formatting/parsing data from a csv file to the google sheet (I'm still learning python !). </p>
  
  <p>So here is the first part of my code :</p>
  
  <pre><code>def add_todo():
  
      credentials = get_credentials()
      http = credentials.authorize(httplib2.Http())
      discoveryUrl = ('https://sheets.googleapis.com/$discovery/rest?'
                      'version=v4')
      service = discovery.build('sheets', 'v4', http=http,
                                discoveryServiceUrl=discoveryUrl)
  
      spreadsheetId = 'spreadsheetidhere'
      rangeName = 'A1:A'
      # https://developers.google.com/sheets/guides/values#appending_values
      values = {'values':[['Hello Saturn',],]}
      result = service.spreadsheets().values().append(
          spreadsheetId=spreadsheetId, range=rangeName,
          valueInputOption='RAW',
          body=values).execute()
  
  if __name__ == '__main__':
      add_todo()
  </code></pre>
  
  <p>I didn't write it myself and it's working perfectly. </p>
  
  <p>Here is the second part of my code :</p>
  
  <pre><code>test = []
  with open('data.csv', 'rb') as f:
      reader = csv.reader(f)
      for row in reader:
              test.append(row)
  </code></pre>
  
  <p>It's also working properly, even though I don't really know how I should mix it with the first part of my code. I've done this:</p>
  
  <pre><code>test = []
  
  def add_todo():
      with open('snap.csv', 'rb') as f:
          reader = csv.reader(f)
          for row in reader:
                  test.append(row)
      credentials = get_credentials()
      http = credentials.authorize(httplib2.Http())
      discoveryUrl = ('https://sheets.googleapis.com/$discovery/rest?'
                      'version=v4')
      service = discovery.build('sheets', 'v4', http=http,
                                discoveryServiceUrl=discoveryUrl)
  
      spreadsheetId = '1UJGs-gJCIUDv5jg5-p0MPEqsokYu5k2MfJ8A5oBkpWs'
      rangeName = 'A1:A'
  
      # https://developers.google.com/sheets/guides/values#appending_values
      values = {'values':[['Hello Saturn',],]}
      result = service.spreadsheets().values().append(
          spreadsheetId=spreadsheetId, range=rangeName,
          valueInputOption='RAW',
          body=values).execute()
  
  if __name__ == '__main__':
      add_todo()
  </code></pre>
  
  <p>As you can guess my main concern is how I should proceed to pass the data from the <code>test</code> array to the spreadsheet values <code>values = {'values':[['Hello Saturn',],]}</code></p>
  
  <p>I wanted to do something like this : <code>values = {'values':[test]}</code> but obviously it doesn't work. </p>
  
  <p>To sum up, here is my csv file :</p>
  
  <pre><code>data1,data2,data3,data4,...
  value1x,value2x,value3x,value4x,...
  value1y,value2y,value3y,value4y,...
  value1z,value2z,value3z,value4z,...
  </code></pre>
  
  <p>And here is what I want in my spreadsheet :</p>
  
  <pre><code>data1   data2   data3   data4 //col name
  value1x value2x value3x value4x //row1
  value1y value2y value3y value4y //row2
  etc...
  </code></pre>
  
  <p>I'm totally lost between <code>array</code>, <code>list</code>, json format. </p>