6

I'm struggling to get a search cursor to work on a joined table view.

I've used search cursors before, but never on data that has been joined. Arcpy keeps saying that some of my joined fields don't exist.

I used arcpy.ListFields() and sure enough, the fields are there. Some of them look different though. They look like this:

Shapefile1.FID Shapefile1.name Shapefile1.LPOLY source_id title author

My search cursor code:

searchRows = arcpy.SearchCursor(theJoinedView)

for row in searchRows:
    if row.source_id == None:
        arcpy.AddMessage(row.Shapefile1.FID)

It says Shapefile1.FID does not exist, when it should. Any ideas?

1 Answer 1

10

There are two ways to get attribute values using cursors. First, you could use a descriptor with the field name. This is what your code does, where you have row followed by a . followed by the field name. Second, you can use the getValue method of the row class, and pass in the field name as a string.

Although row.FID is perfectly valid, row.Shapefile1.FID confuses Python, because it thinks you want the FID property of the Shapefile1 property of row, when in fact you just want the Shapefile1.FID property of row. To avoid confusion, you should use getValue. So instead of doing this:

row.Shapefile1.FID

Try this:

row.getValue("Shapefile1.FID")
1
  • @user1191849 Glad to hear that! Be sure to mark the question as answered (the checkmark button) when you get a chance.
    – dmahr
    Nov 15, 2012 at 1:15

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.