AnsweredAssumed Answered

How to update a feature's attributes via a CSV file with Python

Question asked by aatkins_cegis on Jun 19, 2015
Latest reply on Jun 19, 2015 by iamurray

I have a CSV file that contain fields that denote, account number, a path to a tiff image and type of account (sewer, water, etc). I'd like to update my Account feature class with the path of the tiff file (for hyperlinking) for matching accounts. At first this sounded pretty simple, just use a search cursor and an update cursor within nested for loops and tada...feature updated!  Well for some reason it's not working and I don't know why. I've tried using nested for loops, I've tried creating the cursors via with statements and i can't get it to work.

 

here's the portion of the code I'm having issue with:

 

searchCSV = arcpy.da.SearchCursor(outputcsvlocation2, ["AccountNumber","Path","Type"])
updateAccount = arcpy.da.UpdateCursor(fc, ["AcctNum","B_SCAN", "W_SCAN", "S_SCAN", "ST_SCAN"])

for row in searchCSV:
    for line in updateAccount:
        if row[0] == line[0]:
            print"This is where I'd update the feature!"

 

 

To keep things simple, I've been using smaller datasets; my csv file only has two records, with account numbers 101010000 & 101011002 and my feature class only has five features with account numbers: 101010000, 101000100, 101011000, 101011001, 101011002.

 

Following my logic, my print statement should have printed twice, but it didn't print at all?  I know my issue is some sort of logic, but I can't quite see it. please help!

 

fyi, I also tried this:

with arcpy.da.SearchCursor(outputcsvlocation2, ["AccountNumber","Path","Type"]) as searchCSV:
    with arcpy.da.UpdateCursor(fc, ["AcctNum","B_SCAN", "W_SCAN", "S_SCAN", "ST_SCAN"]) as updateAccount:
        for row in searchCSV:
            for line in updateAccount:
                if row[0] == line[0]:
                    print"This is where I'd update the feature!"

Outcomes