how to make fxn argument work with setting a field value

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
RuntimeError: Row: Field rankFld does not exist
A field called rankFld does not, should not exist. rankFld is
"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")
##
 
M

MRAB

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
RuntimeError: Row: Field rankFld does not exist
A field called rankFld does not, should not exist. rankFld is
"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")
##
The documentation mentions "getValue" and "setValue":

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000
 
M

MRAB

I have tried row.setValue(rankFld) = i for line 14. Get syntax error
- cant assign to function call

Of course you can't assign to a function call!

It's:

row.setValue(rankFld, value)

and:

value = row.getValue(rankFld)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top