Printing Field name Using Search Cursor on a Joined Field

935
4
Jump to solution
02-06-2012 11:37 AM
MikeMacRae
Occasional Contributor III
Hello,

I am trying to print out the values in a field using a cursor search on a field which I have have joined.

I have created a field list and printed it, and i get all the indexed field names, (i.e. SO_SOIL_P.SITE) which is great, but when I try to use the field name when I print the row's value in a cursor search, it's telling me the field doesn't exist. I think it's the processor is having troubles handling the 2 periods in the field ID for the row (i.e. row.SO_SOIL_P.SITE), but it also doesn't like row.SITE. Can anyone suggest a way to write this line to have the values returned properly? Please see the comments at the bottom of the script.

Thanks,
Mike

Code:
import arcpy from arcpy import env  env.overwriteOutput = True  # Local variables: SOIL_P_TERR_Spatial = "Z:\\ESRI\\Geodatabase\\Test1.gdb\\SOIL_P_TERR_Spatial" SO_SOILSCHEM_T = "Z:\\ESRI\\Geodatabase\\Test1.gdb\\SO_SOILSCHEM_T" SO_SOIL_P = "Z:\\ESRI\\Geodatabase\\Test1.gdb\\SO_SOIL_P" v_smu = "\"smu\"" v_spatial_ = "\"spatial\"" soiltable = "soiltable" v_smu2 = "\"smu\""   arcpy.AddIndex_management(SO_SOIL_P, "SITE;SITE_ID;LOCATION;LSD", "SO_SOIL_P_index", "NON_UNIQUE", "ASCENDING")  # Process: Make Feature Layer arcpy.MakeFeatureLayer_management(SO_SOIL_P, v_smu)  # Process: Add Join arcpy.AddJoin_management(v_smu, "SITE_ID", v_spatial_, "SITE_ID", "KEEP_ALL")  # Process: Make Table View arcpy.MakeTableView_management(SO_SOILSCHEM_T, soiltable)  # Process: Add Join (2) jointables = arcpy.AddJoin_management(v_smu2, "SO_SOIL_P.SITE_ID", soiltable, "SITE_ID", "KEEP_ALL")    fieldList = arcpy.ListFields(jointables)  # This prints all the fields in the above joins successfully. for field in fieldList:     print field.name        rows = arcpy.SearchCursor(jointables)  for row in rows:      # This will print the unicode row      print row      # This print will error out, saying the field doesn't exist, but in the field list about, it does      print row.SO_SOIL_P.OBJECTID      # I get the same error when I try this as well      print row.OBJECTID
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LoganPugh
Occasional Contributor III
Not sure what to tell ya, it works for me:
>>> fc = r"C:\Program Files\ArcGIS\DeveloperKit10.0\Samples\data\SanFrancisco\SanFrancisco.gdb\Transportation\Streets" >>> table = r"C:\Program Files\ArcGIS\DeveloperKit10.0\Samples\data\SanFrancisco\SanFrancisco.gdb\Streets_DailyProfiles" >>> featLyr = arcpy.MakeFeatureLayer_management(fc) >>> tblView = arcpy.MakeTableView_management(table) >>> arcpy.AddJoin_management(featLyr, "ID", tblView, "NETWORK_ID") <Result 'Streets_Layer'> >>> rows = arcpy.SearchCursor(featLyr) >>> row = rows.next() >>> row.getValue("Streets.ID") 78400003854190.0 >>> row.getValue("Streets_DailyProfiles.NETWORK_ID") 78400003854190.0


I assume you used a closing quote in your second example, and just missed it on the forum post?

View solution in original post

0 Kudos
4 Replies
LoganPugh
Occasional Contributor III
Try row.getValue("SO_SOIL_P.OBJECTID") instead. You could also use a variable instead of a string literal, i.e. row.getValue(fieldName), where fieldName is a variable assigned previously.
0 Kudos
MikeMacRae
Occasional Contributor III
Hey thanks for the response Logan.

I've tested this, and row.Getvalue works on the parent table table (SO_SOIL_P), but only when you script it as follows (e.g. without the table heading. It won't work with the table heading included):

print row.getValue("OBJECTID")


When I try to pull values from a field in one of the joined tables it errors out again using either of the following:

print row.getValue("SITE_ID")


print row.getValue("SO_SOILSCHEM_T.SITE_ID)


I'm not sure if it can recognize the double join?
0 Kudos
LoganPugh
Occasional Contributor III
Not sure what to tell ya, it works for me:
>>> fc = r"C:\Program Files\ArcGIS\DeveloperKit10.0\Samples\data\SanFrancisco\SanFrancisco.gdb\Transportation\Streets" >>> table = r"C:\Program Files\ArcGIS\DeveloperKit10.0\Samples\data\SanFrancisco\SanFrancisco.gdb\Streets_DailyProfiles" >>> featLyr = arcpy.MakeFeatureLayer_management(fc) >>> tblView = arcpy.MakeTableView_management(table) >>> arcpy.AddJoin_management(featLyr, "ID", tblView, "NETWORK_ID") <Result 'Streets_Layer'> >>> rows = arcpy.SearchCursor(featLyr) >>> row = rows.next() >>> row.getValue("Streets.ID") 78400003854190.0 >>> row.getValue("Streets_DailyProfiles.NETWORK_ID") 78400003854190.0


I assume you used a closing quote in your second example, and just missed it on the forum post?
0 Kudos
MikeMacRae
Occasional Contributor III
Hey Logan,

Thanks for posting that. I see where my error is now. I was trying to loop though the variable used for the original table instead of reading from the feature layer I created. I only noticed that when I compared what I had to yours. This works now. Thanks for the help!

Mike
0 Kudos