AnsweredAssumed Answered

Use variable inside Search cursor

Question asked by leftieant76 on Aug 16, 2012
Latest reply on Aug 17, 2012 by leftieant76
Hi - Python rookie making a pest of himself again.

This continues on from the question I asked y/day about using variables inside an arcpy function. This is the next roadblock I have hit.

My code includes a Search cursor, that will return the value of a field, which is then used to create the name of a text file. I am trying to make my code dynamic, with the intention that once it is complete and running I will turn it into a toolbox tool and allow user input.

As such I'm trying to make the name of the field that is being queried dynamic, so that the user can pick. However I cannot work out how to do this.

Code below:

dataset_tocheck_namefield = "BURNNAME" # the field from the dataset to check that will be used to name the output files . . . . for feature in InputDataCursor: # for loop will create text file for output results         fulloutputpath = checkresult_outputlocation + "\\" + "ValuesCheck" + "_" + feature.BURNNAME + "_" + checktime + ".txt" #variable with text file name including feature name, BURNNAME hardcoded as currently cannot work out how to pass variable to this.         print fulloutputpath #test to see that variable creates correctly         output_text = open(fulloutputpath,"w") #creates text file in location specified by fulloutputpath under a variable called output_text             # additional code goes in here         output_text.close()


Ideally where I have feature.BURNNAME, this would be feature.[whatever the value of dataset_tocheck_namefield] is.

I've tried creating the entire expression as a variable, but the code views it literally, rather than returning that value from the cursor.

Any ideas?

Outcomes