N
noydb
What do I need to do to line 14 code below to get it to recognize the
field name and not the argument name?
I get this error with below code at line 13, the print row.rankFld
line
"RANKa" (in this first iteration), which does exist (gets added in
line 6, verified).
Line 14 fails too, if 13 is commented out.
##
import arcpy
fc = r"C:\test\scratch.gdb\sort_test1"
def rank(inFC, outFC, scoreFld, popFld, rankFld):
arcpy.AddField_management(inFC, rankFld, "LONG")
arcpy.management.Sort(inFC, outFC, [[scoreFld, "DESCENDING"],
[popFld, "DESCENDING"]])
i = 0
print rankFld # >RANKa
rows = arcpy.UpdateCursor(fc)
for row in rows:
i = i + 1
print row.rankFld
row.rankFld = i ## line 14
rows.updateRow(row)
return sortedFC
#
out1 = r"C:\test\scratch.gdb\rankfxn6"
out2 = r"C:\test\scratch.gdb\rankfxn7"
rank(fc, out1, "SCOREa", "COUNT1", "RANKa")
rank(out1, out2, "SCOREb", "COUNT2", "RANKb")
##
field name and not the argument name?
I get this error with below code at line 13, the print row.rankFld
line
A field called rankFld does not, should not exist. rankFld isRuntimeError: Row: Field rankFld does not exist
"RANKa" (in this first iteration), which does exist (gets added in
line 6, verified).
Line 14 fails too, if 13 is commented out.
##
import arcpy
fc = r"C:\test\scratch.gdb\sort_test1"
def rank(inFC, outFC, scoreFld, popFld, rankFld):
arcpy.AddField_management(inFC, rankFld, "LONG")
arcpy.management.Sort(inFC, outFC, [[scoreFld, "DESCENDING"],
[popFld, "DESCENDING"]])
i = 0
print rankFld # >RANKa
rows = arcpy.UpdateCursor(fc)
for row in rows:
i = i + 1
print row.rankFld
row.rankFld = i ## line 14
rows.updateRow(row)
return sortedFC
#
out1 = r"C:\test\scratch.gdb\rankfxn6"
out2 = r"C:\test\scratch.gdb\rankfxn7"
rank(fc, out1, "SCOREa", "COUNT1", "RANKa")
rank(out1, out2, "SCOREb", "COUNT2", "RANKb")
##