2

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 arcpy.sa import *
import os
workspace = r"X:\Auftrag2015円1415154円_Armasuisse_GHK04円_Arbeitsordner\VoF\Armasuisse_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(field.name)
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?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Dec 29, 2015 at 11:01
3
  • 1
    Please replace the picture of your code with a code snippet as text so that it can be searched as well as copy/pasted for testing. Commented Dec 29, 2015 at 11:05
  • Please expand upon "SearchCursor object at 0x14A522A0"...is this coming back in an error? the console? as a result? Commented Dec 29, 2015 at 13:04
  • Can you post the line of code that causes the error, as well as the entire error? Commented Dec 29, 2015 at 16:56

1 Answer 1

3

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"
answered Dec 29, 2015 at 23:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.