import arcpy
from arcpy import env
env.workspace = r"Z:\IOR\2012\2012_Geodatabase_UTM\DOMAIN_CODE_TABLES.gdb"
for x in arcpy.SearchCursor("ANHIC_RANK_S"):
print x.S_RANK
print x.DESCRIPTION
for y in arcpy.SearchCursor("ANHIC_RANK_G"):
print y.G_RANK
print y.DESCRIPTION
with arcpy.da.UpdateCursor("ANHIC_RANKING_FINAL", ["ANHIC_RANKING", "DESCRIPTION"]) as cursor:
for row in cursor:
row.ANHIC_RANKING = x.S_RANK + y.G_RANK
row.DESCRIPTION = x.DESCRIPTION + " + " + y.DESCRIPTION
c.updateRow(row)
for row in cursor: row[0] = x.S_RANK + y.G_RANK row[1] = x.DESCRIPTION + " + " + y.DESCRIPTION cursor.updateRow(row)
import arcpy # setting workspace and then using the data name is better s_rank_fc = r"path_to_your_data\s_rank.shp" g_rank_fc = r"path_to_your_data\g_rank.shp" anhic_fc = r"path_to_your_data\anhic.shp" rows_s = arcpy.SearchCursor(s_rank_fc) # use list comprehension to create a list of lists # each item is a list of two values rank and description s_rank_list = [[row_s.CLASS, row_s.CLASS_DESC] for row_s in rows_s] rows_g = arcpy.SearchCursor(g_rank_fc) # use list comprehension to create a list of lists # each item is a list of two values rank and description g_rank_list = [[row_g.CLASS, row_g.CLASS_DESC] for row_g in rows_g] # zip two lists s_g_list = zip(s_rank_list, g_rank_list) # open an UpdateCursor rows = arcpy.UpdateCursor(anhic_fc) i = 0 # this index is used to extract values from the zipped list for row in rows: s_rank_desc = s_g_list[0] s_rank = s_rank_desc[0] s_desc = s_rank_desc[1] g_rank_desc = s_g_list[1] g_rank = g_rank_desc[0] g_desc = g_rank_desc[1] row.CLASS = s_rank + g_rank row.CLASS_DESC = s_desc + "; " + g_desc rows.updateRow(row) i += 1 del row del rows
import arcpy
from arcpy import env
env.workspace = r"Z:\IOR\2012\2012_Geodatabase_UTM\DOMAIN_CODE_TABLES.gdb"
rankList = []
descList = []
z = 1
# set a search cursor to create every combination of x + y for both the RANK fields and the DESCRIPTION fields and build a list for each
for x in arcpy.SearchCursor("ANHIC_RANK_S"):
for y in arcpy.SearchCursor("ANHIC_RANK_G"):
rankList.append(x.S_RANK + y.G_RANK)
descList.append(x.DESCRIPTION + " + " + y.DESCRIPTION)
# Open an insert cursor to insert the correct number of rows in the new table
insertCursor = arcpy.InsertCursor("ANHIC_RANKING_FINAL")
z = 1
while z <= len(rankList):
row = insertCursor.newRow()
rows.insertRow(row)
z +=1
# zip each list
rank = zip(rankDict)
desc = zip(descDict)
# open an UpdateCursor on the final table
rows = arcpy.UpdateCursor("ANHIC_RANKING_FINAL")
i = 0 # this index is used to extract values from the zipped list
for row in rows:
row.ANHIC_RANKING = rank[0]
row.DESCRIPTION = desc[0]
rows.updateRow(row)
i += 1
del row
del rows