I have a feature class with a number of fields, two of wich are key fields, named key and front, and secondary fields named key_n and front_n.

The thing is I need to search in the whole table for any instances of key values where the front equals the front_n value (key+front = key+front_n), as the basis for calculating the key_n value.

I have tried with arcpy.da.UpdateCursor, but haven't got it, since, to my view, the arcpy.da.UpdateCursor compares only values within the current row, and the provided examples with ArcGis don't explore this possibility.

This is the code I've gotten lately, to no success. In this case, the fields cvegeo and cveft are to be searched as a match to cvegeo + cveref1, in which case, the cvevial1 and cveseg1 fields are to be carried from the record where cvegeo+cveft are taken originaly.

import arcpy
import sys

frentes = arcpy.GetParameterAsText(0)
#frentes = arcpy.GetParameterAsText(1)

with arcpy.da.SearchCursor(frentes, campos) as scursor:
    for row in scursor:
        abuscar = row[0]
        frente = row[1]
        clave_vial = row[2]
        clave_seg = [3]
        with arcpy.da.UpdateCursor(frentes, campos) as ucursor:
           for urow in ucursor:
               if (urow[0] == abuscar and urow[8] == frente):
                   urow[9] = clave_vial
                   urow[10] = clave_seg
  • That looks like it should work, if I've understood your question correctly. Exactly what isn't working? Are you getting an error, or just no updates? – Evil Genius Sep 4 '15 at 17:51
  • I get this error: Traceback (most recent call last): File "D:\python\frentes.py", line 19, in <module> ucursor.updateRow(urow) TypeError: value #10 - unsupported type: list – Ricardo Espejel Cruz Sep 4 '15 at 17:53

You have a syntax error in your outer loop. Instead of assigning the value of the 4th field to clave_seg, you have given it the value of [3], which is a list and ArcGIS doesn't know what to do with it.

Change clave_seg = [3] to clave_seg = row[3]:

  • Jesus, it was so obvious! Apparently the code is now working, thank you very much! Greetings from México! :) – Ricardo Espejel Cruz Sep 4 '15 at 18:03
  • @RicardoEspejelCruz if it answers your question then you can click the Accept button (green tick) to reward the answerer. – PolyGeo Sep 4 '15 at 20:24

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.