Update Cursor error in file geodatabase: RuntimeError: An expected Field...

2652
1
08-01-2013 09:43 AM
CharlesKline
New Contributor
I'm trying to replace <NULL> values in a number of fields for a shapefile in a file geodatabase. The hope is that once I do this, field calculator will be friendlier in the model I'm building. Below is the part of the script that is giving me trouble and the error. I repeat this section for each field. I've based my code on a tutorial from Paul Zandbergen's Python Scripting for ArcGIS book (I'm new to python) and have scoured forums for solutions with no luck. The line the error references is the "for row in cursor:" line. All lines before this section are just import, workspace and # lines.

#Update ElevSTD to replace NULL with 0.
delimElev = arcpy.AddFieldDelimiters(fc, ["ElevSTD"])
cursor = arcpy.da.UpdateCursor(fc, ["ElevSTD"], delimElev + ' = None')
for row in cursor:
    row[0] = 0
    cursor.updateRow(row)
del row
del cursor

Traceback (most recent call last):
  File "C:\Python27\ArcGIS10.1\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Arkansas GIS Appendix\ReplaceNulls.py", line 14, in <module>
    for row in cursor:
RuntimeError: An expected Field was not found or could not be retrieved properly. [Cores_SpJnSoilsVar]



Thanks for any help or insight you can provide!
Tags (2)
0 Kudos
1 Reply
CharlesKline
New Contributor
Nevermind, fixed it! I checked out this forum discussion for help and it worked:

http://forums.arcgis.com/threads/89511-Change-Nulls-to-Blanks

Here is my working code if anyone cares to know:

#Update ElevSTD to replace NULL with 0.
delimElev = arcpy.AddFieldDelimiters(fc, "ElevSTD")
cursor = arcpy.da.UpdateCursor(fc, "ElevSTD", delimElev + ' IS NULL')
for row in cursor:
    row[0] = 0
    cursor.updateRow(row)
del cursor
0 Kudos