Creating a CSV file from an algorithm's output table

A handy snippet that dumps a TableData into a CSV file

# -*- coding: utf-8 -*-
import numpy
import os

import s4l_v1.analysis as analysis

def to_csv(file_path, table):
	import csv

	data = table.ToList()
	col_keys = [""]
	col_keys.extend( [k.replace(',', '') for k in table.ColumnKeys()] )
	row_keys = [k.replace(',', '') for k in table.RowKeys()]

	with open(file_path, 'wt') as outcsv:   	
		writer = csv.writer(outcsv, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL, lineterminator='\n')
		for i, key in enumerate(row_keys):
			row = [key, ]
	print "File written to {}".format(file_path)

if __name__ == '__main__':

     # ... Assume here code to evaluate a pipeline ...
     table = surface_average_J_evaluator.Outputs["Surface-Average Report [ICNIRP 1998]"].Data
     print( "Info: table is of type {}".format( type(data) ) )
     to_csv( os.path.join(basedir, "icnirp1998.csv"), table)