I keep getting the following error and can't figure out why... I'm new to Python and I'm trying to figure out how to iterate through all feature classes within a geodatabase (because they all have the same attributes) and remove old data from certain fields if new data exists in another field for the same record.Traceback (most recent call last):
File "...", line 31, in <module>
with arcpy.UpdateCursor(fc,fields) as cursor:
AttributeError: __exit__
And here's my script...#This script is designed to remove legacy accuracy data from a file
#geodatabase if updated accuracy data exists. Legacy accuracy data are
#stored in each feature class under the following field names: B, C,
#D, E, F, G, H, I, J, K, and L. Current accuracy data is stored in a
#field called A. The script evaluates the value in the A field, if the
#value is greater than zero and not null the data in the legacy fields
#for that record need to be set to zero or Null if it is a string
#field.
import arcpy
#Define a workspace
arcpy.env.workspace = r"C:\Example.gdb"
#Create a list of feature classes
fcList = arcpy.ListFeatureClasses()
#Assign variable fields
fields =("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L")
#Loop through each feature class and set to zero or Null the values in
#the legacy accuracy fields (B-L) if data exists in the A field for
#that record
for fc in fcList:
with arcpy.UpdateCursor(fc,fields) as cursor:
for row in cursor:
if (row[0] > 0 and row[0] <> "<Null>"):
row[1] = 0
row[2] = 0
row[3] = 0
row[4] = 0
row[5] = 0
row[6] = 0
row[7] = "<Null>"
row[8] = "<Null>"
row[9] = "<Null>"
row[10] = "<Null>"
row[11] = "<Null>"
cursor.updateRow(row)
Any direction would be appreciated! Thanks.Kerry