Im running my script in ArcGIS 10.2 and the dialog window says completed, but the empty fields in the 'SoilsType' row of the 'mSoils' Feature Class aren't getting populated with the values from the 'SoilsType' field from the 'mLanduse' Feature Class.

cur = arcpy.da.SearchCursor(mLanduse, lField)
for row in cur:
 cur2 = arcpy.da.UpdateCursor(mSoils, sField)
 for row2 in cur2:
     if row2[0] == '' or row2[0] is None:
         row2[0] = lField
  • I think the problem is in your cursor statements, what version of ArcGIS are you using?
    – artwork21
    Commented Apr 27, 2015 at 12:31
  • with arcpy.UpdateCursor(Soils, query) as cursor: - I don't see where Soils is defined. Commented Apr 27, 2015 at 12:33
  • 1
    Not an answer to your question, but when you use the with...as cursor format, there's no need to del row, rows. They're automatically deleted at the end of the with block. Also, are you sure you have empty (not Null) SoilType values?
    – recurvata
    Commented Apr 27, 2015 at 12:33
  • 7
    I'm not sure I understand what you are trying to do with both your cursors. You are defining a search cursor but are not looping through the rows object. Can you edit your question and provide more background information what you are trying to do with the landuse and soils layers?
    – artwork21
    Commented Apr 27, 2015 at 12:57
  • Perhaps research here and elsewhere on "arcpy cursor where clause field value empty". I think the problem is with query and the syntax you are using there.
    – PolyGeo
    Commented Apr 27, 2015 at 22:38

4 Answers 4


Instead of going the python route, I would recommend using this sequence of geoprocessing tools:

  1. Create new field in soil table called layer, and field calculate it with the value "soil"
  2. Perform union on soil layer and land use (soil first input and land use second input)

The union process will help you deal with soil features that span multiple land use features. This will bring over the other soil type value/field from the land use table into one table (soil_landuse_union)

  1. Finally, select records in soil_landuse_union that have a value of "soil" in the layer field that do not have a soil type and populate the soil type field with the unioned land use soil type field/value

If you have to perform this operation frequently, you could create a model or python script using the geoprocessing tools/steps above.

  • the script is taking longer to work, ie scroll bar moving heaps in dialog window, but still no values being populated.
    – Mark W
    Commented Apr 29, 2015 at 12:32
  • +1 Wrapping cursors in with statements is the preferred method for working with cursors.
    – Aaron
    Commented Apr 29, 2015 at 12:37
  • Is that saying that mLanduse has the blank fields? Because the blank fields are in mSoils.
    – Mark W
    Commented Apr 29, 2015 at 12:42
  • You want to perform the update on mSoils or mLanduse layer?
    – artwork21
    Commented Apr 29, 2015 at 12:44
  • 1
    Are you wanting to select each soil feature within the land use feature, if soil feature soil field is blank than populate if with the intersected land use soil field value?
    – artwork21
    Commented Apr 29, 2015 at 13:01

Change your exception handler to this:

# Return any errors   
except Exception as e:

Now open py file in IDLE and try to run. See what error you have.

ED|T: for row3 in row2: = you'll get a "row2 is undefined" error here in case you'll manage to get here :) First clean up syntax errors first and people here can help you to solve the issue.

  • I changed the exception handler as you suggested and run the script in IDLE, checked module and no syntax errors and no other errors.
    – Mark W
    Commented Apr 29, 2015 at 22:43

One of the primary problems is in the following line of code:

rows3 = mLanduse

Here you are trying to pass a feature class (mLanduse) into the attribute table, which cannot be done. Instead, you need pass a integer, float, string etc. Perhaps you meant to do the following:

rows3[0] = row[0]
  • When I run the script in ArcGIS, the dialog windows is saying "Executing SelectByLocation", succeeded at the 'time' and script complete. However, the blank values are not being populated in the 'Soils' Feature Class.
    – Mark W
    Commented Apr 29, 2015 at 11:34
  • That's not where the script will fail--it is at the part I describe in the post.
    – Aaron
    Commented Apr 29, 2015 at 11:36
  • I have updated my script with your answer and checked 'Soils' feature class and values still didn't come through.
    – Mark W
    Commented Apr 29, 2015 at 11:39
  • You will need to provide some visual examples of your data and intended output so that we have some idea of what you are trying to accomplish.
    – Aaron
    Commented Apr 29, 2015 at 11:49

You're making a big assumption with your SearchCursor/UpdateCursor pairing that the features from both match up exactly in order. That might be 'okay' for your data now, but it might not always be.

If the features match up spatially, which seems likely based on your question, then just use the Spatial Join tool: http://desktop.arcgis.com/en/desktop/latest/tools/analysis-toolbox/spatial-join.htm


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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