2

I have a question regarding an answer to "Exporting data from 'collect values' output in ArcGIS model builder". I'm trying to do the same thing as the author to that question and I've followed the steps and the code in that answer. The code I am using is below:

multivaluesToCsv(r"%CSV File%", "%Feature Class Name%", "%NNZScore Value%", "%NNExpected%", "%NNObserved%", "%PValue%", "%NNRatio%")


import csv

def multivaluesToCsv(csvfile, featureclassnames, nnzscorevalue, nnexpectedvalue, nnobservedvalue, pvaluescore, nnratiovalue):
with open(csvfile, 'wb') as f:
 w = csv.writer(f)
 columnNames = ["FC", "NNZ", "NNE", "NNO", "PV", "NNR"]
 w.writerow(columnNames)
 rows = zip(*map(lambda x: x.split(';'), [featureclassnames, nnzscorevalue, nnexpectedvalue, nnobservedvalue, pvaluescore, nnratiovalue]))
 w.writerows(rows)

My problem is that the CSV file is only being populated with the final row of values. The titles all appear but only the last iteration's data is included. Any suggestions?

4
  • There is not enough information to go on here. What does the rest of your model look like? A screenshot would be helpful. Also note the last two paragraphs of my answer, about the "quirk" with iterators (try nesting the iterated part in a sub-model).
    – blah238
    Commented Jun 7, 2012 at 3:05
  • @whuber this is a Calculate Value tool, not Calculate Field, so there is no implicit iteration within it.
    – blah238
    Commented Jun 7, 2012 at 3:07
  • 1
    @Abehrer, please note I have updated my answer to the linked question.
    – blah238
    Commented Jun 7, 2012 at 6:45
  • Thanks, @blah238. I will delete that comment to avoid misleading people.
    – whuber
    Commented Jun 7, 2012 at 15:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.