I have a CSV file called Modifications. The header has two entries, Rental Object and Rental Object Name. The Rental Object is a string that has matching values in a FGDB feature class where the column is called Property_Ref. This attribute table also contains a field called Descriptio. I need to update this Descriptio with the values from Rental Object Name in the CSV. The Rental Object in the CSV and the Property_Ref match. I'm not sure how to complete this. Below is as far as I've progressed.

# Update Records to be Archived:
import csv, arcpy
fc = "U:/Data/Lease_Plans.gdb/LeasePlans_SAP_NOs_Descs"
Modifications= "U:/Data/Rental_Object_Modifications.csv"

#Read the CSV File
with open(Modifications, 'r') as f:
    reader = csv.reader(f)
    mydict = dict((rows[0],rows[1]) for rows in reader)

fc_fields = ('Property_Ref','Descriptio')

with arcpy.da.UpdateCursor(fc, fc_fields) as cursor:
    for row in cursor:
        #Not sure how to structure this.

del cursor
  • Is Rental Object value unique for all rows in the CSV file?
    – Hornbydd
    Jan 18, 2018 at 17:40
  • 2
    you can join a csv file with a table in arcmap. have you tried joining and then using the field calculator to populate the desired field?
    – Brad
    Jan 18, 2018 at 17:40
  • Thanks, I am hoping to make this part of a much large automation project eventually so was trying to avoid a join.
    – Dunuts
    Jan 19, 2018 at 10:51

1 Answer 1


If the dictionary is built properly, and it looks like it is, you should be able to compare the 'Property_Ref' values to the dictionary keys ('Rental_Object') with a loop. You should iterate over the FeatureClass rows and update the 'Descripto' field to the value of the key in my_dict.

Also, don't forget to make the fc_fields variable a list and not a tuple.

fc_fields = ['Property_Ref', 'Descriptio']

with arcpy.da.UpdateCursor(fc, fc_fields) as cursor:
    for row in cursor:
        if row[0] in my_dict:
            row[1] = my_dict[row[0]]
del cursor
  • 2
    No need for del cursor, as garbage collection will delete it at the conclusion of the with block.
    – nmpeterson
    Jan 18, 2018 at 17:57
  • @nmpeterson I keep getting a <da.SearchCursor object> present while running from IDLE. Can you send info on this, please?
    – mdholl6188
    Jan 18, 2018 at 18:05
  • 1
    It's probably just a delay in the automatic garbage collection. I wouldn't be concerned about it. Whatever variables you initialize as part of a with are designed to be temporary, guaranteed to exist only over the life of the with block.
    – nmpeterson
    Jan 19, 2018 at 17:03

Your Answer

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

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