1

I'm trying to use arcpy SearchCursor to iterate through an attribute table, and the only fields that I'm interested are line_code, w_min and ang_ataque. This is not running properly because I got the type error :

"'Row' object is not iterable"

What's wrong in my code?

import arcpy
featureClass="C:\\Users\\andreia.medeiros\\Documents\\ArcGIS\\Trabalho\\Modelo\\linhas_150_5km.shp"

data=arcpy.SearchCursor(featureClass,"","","Line_code;w_min;ang_ataque","Line_code;w_min;ang_ataque")

import collections
d=collections.defaultdict(list)
for Line_code,w_min,ang_ataque in data:
     d[Line_code].append(w_min*ang_ataque)
5
  • 1
    where do you get the error? maybe the shapefile is empty. make sure all the fields exists in the shapefile Commented Sep 16, 2015 at 12:53
  • My shapefile has an attribute table with various fields. I get the error after cycle for. I'm gonna update the code here to show
    – AndM
    Commented Sep 16, 2015 at 12:58
  • What version of arc are you using? If 10.1 or above, this would be easier using the arcpy.da cursors.
    – recurvata
    Commented Sep 16, 2015 at 13:53
  • When using "w_min*ang_ataque", if one is text, you could get a type error! Commented Sep 16, 2015 at 14:07
  • 1
    sorry not to mention, my arcgis is 10.0 w_min and ang_ataque are float and double type
    – AndM
    Commented Sep 16, 2015 at 14:26

1 Answer 1

5

You need to get the row object first, then you can get the field values. So you can't say:

for Line_code,w_min,ang_ataque in data:
...

Instead, try changing your loop to:

for row in data:
     d[row.Line_code].append(row.w_min*row.ang_ataque)
0

Your Answer

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

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