how to make fxn argument work with setting a field value

MRAB python at mrabarnett.plus.com
Thu Sep 8 04:11:07 CEST 2011


On 08/09/2011 02:32, noydb wrote:
> 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



More information about the Python-list mailing list