Exporting simple list (multiline text) to csv/txt files and retrieve it

Hi, I am running parametric daylight analyses and I would like to store a list of ‘pointers’ to 1 or more files on disk so that I can retrieve them at a later stage.

testPts returns a list of points that are used for the analysis (required to map-mesh the results) - it looks like:

  1. {6.25, 0.75, 0.75}
  2. {5.75, 0.75, 0.75}
  3. {5.25, 0.75, 0.75}
  4. {4.75, 0.75, 0.75}
  5. {4.25, 0.75, 0.75}
  6. {3.75, 0.75, 0.75}

annual_analysis_files contains a list of filepaths where the results are stored. it looks like:

  1. C:\ladybug\project_id\annual_daylight\main_folder\iteration_id\annualSimulation\iteration_id_0.ill
  2. C:\ladybug\project_id\annual_daylight\main_folder\iteration_id\annualSimulation\iteration_id_1.ill
  3. C:\ladybug\project_id\annual_daylight\main_folder\iteration_id\annualSimulation\iteration_id_2.ill
  4. C:\ladybug\project_id\annual_daylight\main_folder\iteration_id\annualSimulation\iteration_id_3.ill
  5. C:\ladybug\project_id\annual_daylight\main_folder\iteration_id\annualSimulation\iteration_id_4.ill
  6. C:\ladybug\project_id\annual_daylight\main_folder\iteration_id\annualSimulation\iteration_id_5.ill

I have tried using componets from TTtools and Lunchbox (which force to go via excel) but the writing/saving/clearing sheets appears impossible to sort out and keeps failing regularly.

Is there a simple python script for reading this info into files, allowing for a True/False toggle? The csv or txt file does not need to have an index, but just one value per row - no separator is needed as the list/data tree has one column only.



Does this help?

@Dancergraham thanks. Yes, I had seen that page, however I need to figure out how to amend the code in order to:

  • save lists and not points,
  • create the file if it does not exist,
  • force file overwrite

OK so you can iterate over a list, replacing lines 14 to 18 with something like:

    with open(filename, "wb") as csvfile:
        csvwriter = csv.writer(csvfile,  delimiter=',')
        for line in my_list:
        print "List written sucessfuly to file"

This should create / overwrite the file without prompting you


Thanks @Dancergraham!