jmorante

For loop through UpdateCursor stops after first row

Discussion created by jmorante on May 25, 2012
Latest reply on May 28, 2012 by dkwiens
I am running this script here to try and match some various fields within the same file. So I have setup a search and an update cursor within that file.

However, when I run the script, the main part of the script where the update cursor for loop exists, stops after the first entry. Clearly I am doing something wrong. Is this just a problem with trying to run two cursors in the same file? I figured it would not be a problem since the search cursor should not try and get any kind of lock on the data. Any help would be much appreciated. Code is below.

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
#municLayer = arcpy.mapping.(mxd, "MUNICPIOS")
municLayer = arcpy.UpdateCursor("C:\File")
municSearch = arcpy.SearchCursor("C:\File")

def matchMunic(municipalityname):
    for row in municSearch:
        munictomatch = strip_accents(row.NOM_MUN.upper())
        enttomatch = strip_accents(row.NOM_ENT.upper()[:3])
        stringtomatch = munictomatch+" ("+enttomatch+")"
     print stringtomatch+" =? "+municipalityname
        if municipalityname == stringtomatch:
            print "We have found a match for " + stringtomatch
            municSearch.reset()
            return row.Count
    
    municSearch.reset()
    return 303
            
def strip_accents(string):
    import unicodedata
    return unicodedata.normalize('NFKD', unicode(string)).encode('ASCII', 'ignore')        

for row in municLayer:
    municname = row.Munic
    row.MunicPytho = matchMunic(municname)
    municLayer.updateRow(row)

Outcomes