Select to view content in your preferred language

Row objects in the Data Access module

1723
11
11-06-2012 11:15 AM
ChrisMathers
Deactivated User
Can anyone explain the reasoning behind returning a row object as a tuple when using the Data Access module update cursor? I can understand it with a search cursor, you can dict(zip(cursor.fields,row)) and make a dictionary that lets you call the values by field name. I don't understand how I should be using this without counting to find the field index number in the tuple.  The help docs are not very clear on this topic. It seems like returning a dictionary would be easier for the users. I only just was given permission to update to 10.1 because sp1 is now  out so I may have missed this discussion at an earlier date. So as not to be entirely contrary, I do like the with-as usage for cursor's. That's pretty neat.
Tags (2)
0 Kudos
11 Replies
ChrisSnyder
Honored Contributor
BTW: I have heard that the .da cursors are similar to the way the ArcObjects cursors behave (with an index).
0 Kudos
DavidWynne
Esri Contributor
Maybe there will be someone from the Arcpy team at SERUG this year I can bug about it :D. It was obviously a deliberate choice to make such a big change. Ill use your method for now Chris. tuple.index is a good solution.


Performance is the big reason.  Getting the row back in a tuple that you can pull values by index is a much faster approach than creating a row object and then have to make individual calls to get specific values.

The approach of forming a dictionary and then pulling values out from that is okay, but that is adding overhead just to enhance readability.  I would much rather just add code comment(s) if I need to clarify which field value is which.

-Dave
0 Kudos