I am trying to replace NULL values for -999 in a table inside a gdb. I know how to replace the value for individual fields, but get an error when looping through the complete table.

import arcpy
fc ="C:\gSSURGO.gdb\chorizon_va_1"
fieldList = arcpy.ListFields(fc)

with arcpy.UpdateCursor(fc, [fieldList]) as cursor:
 fRange = range(len(fieldList)) 
 for row in cursor:

     for index in fRange:
         if row[index] == None:
             row[index] = -999 

And this is the error I get:

Runtime error : 'Cursor' object has no attribute '_exit_'

I found some examples using arcpy.da.UpdateCursor, but when I use that I get this error:

Runtime error <type 'exceptions.AttributeError'>: 'module' object has no attribute 'da'

I am using ArcMap 10.0.

  • What version of ArcGIS for Desktop are you using? – PolyGeo Jul 18 '15 at 19:57
  • I am using ArcMap 10.0 – Iced_ Jul 18 '15 at 20:01
  • Just as an aside, I generally find None (NULL) is much more suited to representing absence than a value like -999. Although you haven't elaborated on your reasons, consider that NULL is far less ambiguous than a numerical value, especially if down the track someone other than you will be using the data. In some cases, -999 is s meaningful value in itself. Further, it is easier for someone to filter out None values than to have to guess what value represents NULL and then filter them. – alphabetasoup Jul 19 '15 at 4:42
  • I need to export the data and do some further processing. When I export is as dbf, NULL is converted to zero .. So I use -999 to be able to distinguish zero from NULL values. – Iced_ Jul 19 '15 at 17:53

ArcPy did not have a Data Access module until ArcGIS 10.1. This will explain your second error message.

The only way to specify fields in ArcPy cursors prior to that was by using their names rather than an index.

| improve this answer | |
  • 2
    And arcpy.*Cursors do not support the with statement. – user2856 Jul 18 '15 at 21:53
  • Additionally, you need be careful while doing this row update, since you have different field types as looping the fields (i.e., fieldList) and need to elaborate "-999" differently for some. – fatih_dur Jul 19 '15 at 3:25

I updated to ArcMap 10.2.

This worked for all types of fields:

import arcpy

fc ="C:\gSSURGO_test.gdb\chor_comp_zone1"
fieldObs = arcpy.ListFields (fc)
fieldNames = [] 

for field in fieldObs:

fieldCount = len(fieldNames)

curU = arcpy.da.UpdateCursor(fc, fieldNames)
for row in curU:
         rowU = row 
         for field in range(fieldCount):
                      if rowU[field] == None:
                         rowU[field] = -999
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.