Converting .csv files to .JS via Python

I used the JavaScript data visualization library D3.js and have distributed my work to customers who view them via web browsers. I am lucky if I can upload a .csv file to an online repository. But sometimes I can’t, and web browsers are not allowed to reference local .csv files for security reasons. But they can reference .js files. Here’s a script to convert a .csv file to a .js file. At a high level, this is the process flow:

  1. read data.csv
  2. create a string that is “data = {my JSON objects}”
  3. write to a file data.js

 

source code

Leave a comment