Convert searchcursor object to variable

Convert searchcursor object to variable

Using a python script, i would like to read through a table which features 27 columns. For each row i want to store the value of each column in a variable, so that i can pass the values to a subsequent script as input parameter.

here's what i have so far:

import arcpy from arcpy import env from import * import os workspace = r"X:Auftrag20151415154_Armasuisse_GHK4_ArbeitsordnerVoFArmasuisse_Vof.gdb" arcpy.env.workspace = workspace arcpy.env.scratchworkspace = workspace arcpy.env.overwriteOutput = True Inputdaten_txt = "Batchtable" Attributes = arcpy.ListFields(Inputdaten_txt) Attribute_List = [] for field in Attributes: Attribute_List.append( with arcpy.da.SearchCursor(Inputdaten_txt, Attribute_List) as cursor: for field in Attribute_List: for row in cursor: OBJECTID = ("{0}".format(row[0])) Temp = ("{0}".format(row[1])) CalculationOption = ("{0}".format(row[2])) ElevationModel = ("{0}".format(row[3])) DrainageNetwork_rainfall = ("{0}".format(row[4])) RelativeDrainageElevation = ("{0}".format(row[5])) Elevation_of_input_drainage_network = ("{0}".format(row[6])) ConstantDrainatePlus = ("{0}".format(row[7])) HydrographFile = ("{0}".format(row[8])) CoordinateFile = ("{0}".format(row[9])) Roughness = ("{0}".format(row[10])) FlowBarrier = ("{0}".format(row[11])) DamFailure = ("{0}".format(row[12])) ContinueCalculationFrom = ("{0}".format(row[13])) ContinueTime = ("{0}".format(row[14])) ContinueInundationAsWaterDepth = ("{0}".format(row[15])) DurationOfSimulation = ("{0}".format(row[16])) SavingIntervall = ("{0}".format(row[17])) OutputSwitch = ("{0}".format(row[18])) MapUnits = ("{0}".format(row[19])) HeightUnits = ("{0}".format(row[20])) drainage_units = ("{0}".format(row[21])) MaximumExchange = ("{0}".format(row[22])) Output = ("{0}".format(row[23])) intermed = ("{0}".format(row[24])) LicenseCode = ("{0}".format(row[25])) Execute = ("{0}".format(row[26])) # continue by calling another python script

I'm quite sure that i could be done easier, for instance i would like to automatically generate each variable (e.g. var_1… var_27) using a loop that goes through a list of these variables obtained with the searchCursor function. But whenever i tried, i got stuck at the point where my variable ends up being a "SearchCursor object at 0x14A522A0" instead of the field value in the table. Can anyone tell me the easiest way to get this task done?

Here are two different ways in which you could accomplish the task.

You could create an empty list for each attribute and append to these lists in your search cursor for loop.

OBJECTID =[] Temp =[] with arcpy.da.SearchCursor(Inputdaten_txt, Attribute_List) as cursor: for row in cursor: OBJECTID.append(row[0]) Temp.append(row[1])

A different way to would be to create a single list variable that contains lists within it of each attributes value

lists =[] for i in range(0,len(Attribute_List)): lists.append([]) with arcpy.da.SearchCursor(Inputdaten_txt, Attribute_List) as cursor: for row in cursor: for i in range(0,len(row)): lists[i].append(row[i]) print lists[0] # this should print out a list of all of the OBJECTID values in your table "Batchtable"