Skip to content

Instantly share code, notes, and snippets.

@kennyledet
Created September 8, 2014 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kennyledet/b4f415e48621d783fe95 to your computer and use it in GitHub Desktop.
Save kennyledet/b4f415e48621d783fe95 to your computer and use it in GitHub Desktop.
Convert a CSV file to a Javascript Array
def csv_to_js_array(csv_path):
import csv
import os
attributes = []
values = []
with open(csv_path, "rb") as csvfile:
print csvfile
reader = csv.reader(csvfile)
for row_num, row in enumerate(reader):
if row_num == 1:
attributes = row
else:
values.append(row)
return {"attributes": attributes, "values": values}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment