Function object is not iterable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • susieg
    New Member
    • Jul 2012
    • 2

    Function object is not iterable

    Hi,
    here is a code snippet that is supposed to calculate Value2 by multiplying Wfactor and Value1 for identical object ID's.
    Unfortunately the line with "Value2 =" casts a function object is not iterable error. I am stumped on where it is coming from.
    Code:
    testDict = {}
    for test in helps.getUniqueValues(fc,"ID"):
                Value2 = ([c.getValue("Value1")*c.getValue("Wfactor") for c in arcpy.SearchCursor if c.getValue("ID") == test])
                testDict[t] = Value2
                
                cur = arcpy.UpdateCursor(fc)
                for row in cur:
                    row.setValue("Value2",testDict[row.getValue("ID")])
                    cur.updateRow(row)
    Sorry, I think my indentation got all messed up.
    Happy 4th of July to everyone (in advance)!
    Last edited by bvdet; Jul 3 '12, 10:45 PM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Without knowing arcpy, I would guess arcpy.SearchCur sor should be arcpy.SearchCur sor().

    Comment

    • susieg
      New Member
      • Jul 2012
      • 2

      #3
      Hi bvdet,
      that was a good idea. Adding the parentheses did not solve the issue though.

      Comment

      • dwblas
        Recognized Expert Contributor
        • May 2008
        • 626

        #4
        Code:
        for c in arcpy.SearchCursor
        If searchCursor is a function that does not return an iterable, then it would be the cause. Split the list comprehension into separate statements to see.
        Code:
        for c in arcpy.SearchCursor:
            print c
        
        print "get value =", c.getValue("Value1")
        
        etc.

        Comment

        Working...