1

I'm working through some da.UpdateCursor scripts to make updates to a fgdb. Although the script below works successfully, I want to use the dictionary that I have created rather than the manual [ ] system I have for demo purposes.

Can anyone provide some guidance please as I have researched this quite significantly and can't get an answer after some hours of effort and no error message. (Using Win 7, ArcGIS 10.2, Python 2.7.5)

The code below updates 'book_ref' where it finds the matching 'book_id' in 'seq = .......'

 seq = [[7643, 7625], [9644, 2289]]
 Att_Dict = {}
 for pair in seq:
 Att_Dict[pair[0]] = pair[1]
 with arcpy.da.UpdateCursor(in_fc1, ['book_id', 'book_ref']) as cursor:
 for row in cursor:
 pozzy = row[0]
 if pozzy in Att_Dict:
 row[1] = Att_Dict[pozzy]
 cursor.updateRow(row)

How do I get it to use the values from my dictionary?

seq = {7643: 7625, 
 9644: 2289, 
 4406: 4443, 
 7588: 9681, 
 2252: 7947}
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Aug 20, 2015 at 3:00
0

1 Answer 1

1

To test your code I created a test feature class with two long integer fields:

enter image description here

and ran this code:

import arcpy
in_fc1 = r"C:\Temp\test.gdb\PointFC"
seq = [[7643, 7625], [9644, 2289]]
Att_Dict = {}
for pair in seq:
 Att_Dict[pair[0]] = pair[1]
with arcpy.da.UpdateCursor(in_fc1, ['book_id', 'book_ref']) as cursor:
 for row in cursor:
 pozzy = row[0]
 if pozzy in Att_Dict:
 row[1] = Att_Dict[pozzy]
 cursor.updateRow(row)

which produced the expected result of:

enter image description here

answered Aug 20, 2015 at 23:30
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.