Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 8 down vote accepted

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")
share|improve this answer
    
Thank you! This worked perfectly –  jabeoogie Nov 15 '12 at 1:12
    
@user1191849 Glad to hear that! Be sure to mark the question as answered (the checkmark button) when you get a chance. –  dmahr Nov 15 '12 at 1:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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