AnsweredAssumed Answered

AttributeError: __exit__

Question asked by vshah6 on Mar 14, 2018
Latest reply on Mar 14, 2018 by vshah6

Hello,

 

So I am new to working with cursors and need a little help with my code as I am getting an AttributeError: __exit__ when i run my script. Here's what my code looks like:

 

inTable = r'Layer\Fiber'
routeMilesField = "RouteMiles"
strandsField = "cableSize"
milesField = "FiberMiles"
fields = [strandsField, milesField, routeMilesField]


with arcpy.UpdateCursor(fiberFeatures, fields) as cursor:
    for row in cursor:
        if None in row[:-1]:
            arcpy.AddMessage("Insufficient Strand Data!")
            break
        else:
            row[2] = row[0] * row[1]
            cursor.updateRow(row)

 

Any help is greatly appreciated!

 

Edit:

Revised script based on this article: cursor - AttributeError: __exit__ when trying to use arcpy.UpdateCursor - Geographic Information Systems Stack Exchange 

 

cursor = arcpy.UpdateCursor(fiberFeatures, fields)
for row in cursor:
    if None in row[:-1]:
        arcpy.AddMessage("Insufficient Strand Data")
        break
    else:
        row[2] = row[0] * row[1]
        cursor.updateRow(row)

 

This returns a TypeError: 'Row' object has no attribute '__getitem__' error. I'm new to cursors and what not and definitely need help with this code.

 

Edit 2: Solution based on Joshua's feedback:

 

with arcpy.da.UpdateCursor(fiberFeatures, fields) as cursor:
    for row in cursor:
        if None in row[:-1]:
            arcpy.AddError("Insufficient Strand Data!")
            break
        else:
            row[2] = row[0] * row[1]
            cursor.updateRow(row)

Outcomes