unable to "setValue" on a field

520
2
07-29-2011 10:06 AM
DustinReagan
New Contributor
Hi,

I'm probably overlooking something obvious, but i'm unable to set a value on a field of a feature class.  Here is a short example to show what I am doing.

import arcpy
from arcpy import env

env.workspace = r"X:\temp"

fc = "temp.shp"


desc = arcpy.Describe( fc )

print 'Fields: '
for field in desc.fields:
    print 'Name: ', field.name, 'Type: ', field.type, 'Length: ', repr(field.length)
    

rows = arcpy.SearchCursor( fc )

for row in rows:
    row.setValue("S_T_R", "test")



Here is the output:


Fields:
Name:  FID Type:  OID Length:  4
Name:  Shape Type:  Geometry Length:  0
Name:  TOWNSHIP_N Type:  Double Length:  11
Name:  TOWNSHIP_D Type:  String Length:  1
Name:  RANGE_NUM Type:  Double Length:  11
Name:  RANGE_DIR Type:  String Length:  1
Name:  RECORD_NUM Type:  String Length:  3
Name:  SECTION Type:  Double Length:  11
Name:  ID_FIELD Type:  String Length:  9
Name:  S_T_R Type:  String Length:  12

Traceback (most recent call last):
  File "C:/code/scripts/GIS/addS_T_R.py", line 20, in <module>
    row.setValue("S_T_R", "test")
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\arcobjects.py", line 940, in setValue
    return convertArcObjectToPythonObject(self._arc_object.SetValue(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.


Thanks for any pointers.

Dustin
Tags (2)
0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus
setValue only works with insertcursor or updatecursors, check the help
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001q000000.htm
0 Kudos
DustinReagan
New Contributor
setValue only works with insertcursor or updatecursors


Thank you! I knew I was overlooking something obvious...I looked at this help page multiple times, but overlooked the different cursor types!
0 Kudos