I am trying to set a field value in one feature class (TRU) based on the value of a field in a separate feature class (DerivedBoundaries) that contains the first, using python in ArcGIS 10.1.

I have written a script that iterates through each site boundary, selects all of the TRU features inside of it, and does that pretty well. However, I cannot seem to get my head around how the arcpy.CalculateField_management() function operates.

#Build an array and fill it with all the TempIDs numbers present in the data table
rows = arcpy.SearchCursor(lyr_DerivedBoundaries)
row = rows.next()

TRU_rows = arcpy.UpdateCursor(lyr_TRU)
TRU_row = rows.next()

while row:
    a = row.TempID
    row = rows.next()

    #Set Count equal to the length of the array created in the while loop
    Count = len(TempIDs)

while Position < Count: #iterate through each individual feature by using a definition query
    query = "[TempID] = " + "'" + TempIDs[Position] + "'"
    lyr_DerivedBoundaries.definitionQuery = query

    #center on feature

    #Select all of the TRU Cells within the active Site Boundary

    #Set [Assoc_Site] equal to lyr_DerivedBoundaries.[TempID]
    hopper = '""""' + str(TempIDs[Position]) + '""""'

I have been attempting to make the third argument in the CalculateField function operate based on the syntax I am seeing from copying a successful CalculateField operation as a python snippet from the results window in ArcMap.

Any help is greatly appreciated, I'm open to the possibility that I am going about this is a roundabout way and that there is a better way.


Edit: Just in case, here is the text of the error message I get when the script hits the line with the CalculateField function on it:

Runtime error Traceback (most recent call last): File "", line 43, in File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3129, in CalculateField raise e ExecuteError: ERROR 999999: Error executing function. Expected end of statement Failed to execute (CalculateField).

1 Answer 1


Fixed! Amazing what a few minutes away from the code will do...

The problem was that I was including too many quotation marks when I set the value for 'hopper'. I changed:

hopper = '""""' + str(TempIDs[Position]) + '""""'


hopper = '"' + str(TempIDs[Position]) + '"'

And now it runs just like I want it to!

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.