Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to know how to export in Arcgis a list of values calculated in python script into one of the following data formats: csv, txt, xls, dbase or other. I would also like to know how to create such file in case that it doesnt exist.

The list of values looks like res=(1,2,3,...,x). Each value must be written into a new row.

share|improve this question
Export from what GIS program? – Mapperz Sep 25 '13 at 13:33
up vote 8 down vote accepted

You mention that you computed a list of values in a Python script, so the easiest way to dump that to a csv would be to use the csv module!

import csv

res = [x, y, z, ....]
csvfile = "<path to output csv or txt>"

#Assuming res is a flat list
with open(csvfile, "w") as output:
    writer = csv.writer(output, lineterminator='\n')
    for val in res:

#Assuming res is a list of lists
with open(csvfile, "w") as output:
    writer = csv.writer(output, lineterminator='\n')
share|improve this answer
This is exactly what I was looking for. However it looks that the csv file must already exist. What if it doesnt. How can I create it programmatically? – user21816 Sep 25 '13 at 18:31
@user21816, by using the "w" parameter (short for 'write') for the open() function, you can create a new file at that path. – Paul Sep 25 '13 at 19:24
this method worked for me! my question is this, what if you want the output csv table to be oriented the opposite way from this method? – Andy Witt Aug 12 '15 at 21:00
@AndyWitt, do you mean transposing the rows and columns? – Paul Aug 12 '15 at 21:20
@Paul, that exactly my question – Andy Witt Aug 12 '15 at 21:27

QGIS 1.8 can't edit a CSV file. The workaround is to import the csv file into a db.sqlite table using QGIS's Qspatialite or Spatialite_GUI etc., and then edit the table and export that data back into a table.csv file, if necessary. In QGIS 1.8, DONT export or import into sqlite or spatialite directly from under LAYERS, via right-clicking. It is very slow and may crash. Use the Qspatialite plugin instead to load sqlite databases, and right click from Qspatialite to load into LAYERS for QGIS editing.

Alternately, you can right click on the table.csv file under your QGIS 1.8 LAYERS, export to shapefile, then load "vector" file, changing the file extension to ".*" to see ALL files available, including dbf without associated shapes. It loads the dbf table which can be edited, but if your column name or data widths exceed the shapefile/dbf limit then the data will be truncated. After importing back into a csv file, the table names can easily be restored with a text or spreadsheet editor, for instance Notepad, Gedit or Excel. That additional information is for the posterity of future folks looking over this question for an answer that suits their needs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.