Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #12938 > unrolled thread

how to make fxn argument work with setting a field value

Started bynoydb <jenn.duerr@gmail.com>
First post2011-09-07 18:32 -0700
Last post2011-09-08 16:06 +0100
Articles 4 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  how to make fxn argument work with setting a field value noydb <jenn.duerr@gmail.com> - 2011-09-07 18:32 -0700
    Re: how to make fxn argument work with setting a field value MRAB <python@mrabarnett.plus.com> - 2011-09-08 03:11 +0100
      Re: how to make fxn argument work with setting a field value noydb <jenn.duerr@gmail.com> - 2011-09-08 00:59 -0700
        Re: how to make fxn argument work with setting a field value MRAB <python@mrabarnett.plus.com> - 2011-09-08 16:06 +0100

#12938 — how to make fxn argument work with setting a field value

Fromnoydb <jenn.duerr@gmail.com>
Date2011-09-07 18:32 -0700
Subjecthow to make fxn argument work with setting a field value
Message-ID<7732a253-c834-4578-93eb-930346247e57@b20g2000vbz.googlegroups.com>
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")
##

[toc] | [next] | [standalone]


#12940

FromMRAB <python@mrabarnett.plus.com>
Date2011-09-08 03:11 +0100
Message-ID<mailman.861.1315447873.27778.python-list@python.org>
In reply to#12938
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

[toc] | [prev] | [next] | [standalone]


#12949

Fromnoydb <jenn.duerr@gmail.com>
Date2011-09-08 00:59 -0700
Message-ID<c95f57a0-1c55-45ea-9123-cb252e8657ae@i21g2000yqd.googlegroups.com>
In reply to#12940
> The documentation mentions "getValue" and "setValue":
>
> http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00...- Hide quoted text -
>
> - Show quoted text -

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

[toc] | [prev] | [next] | [standalone]


#12966

FromMRAB <python@mrabarnett.plus.com>
Date2011-09-08 16:06 +0100
Message-ID<mailman.877.1315494376.27778.python-list@python.org>
In reply to#12949
On 08/09/2011 08:59, noydb wrote:
>> The documentation mentions "getValue" and "setValue":
>>
>> http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z00...- Hide quoted text -
>>
>> - Show quoted text -
>
> 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)

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web