rows = arcpy.UpdateCursor("Assets") for row in rows: if row.Processed == "N" and row.Asset_ID == "Asset_Unprocessed.Asset_ID": row.Processed = "Y" rows.updateRow(row) del row del rows
Solved! Go to Solution.
table = 'assets_unprocessed' assetIDList = [] rows = arcpy.SearchCursor(table) for row in rows: assetIDList.append(row.Asset_ID) del row, rows table2 = 'assets' for ID in assetIDList: rows = arcpy.UpdateCursor(table2) for row in rows: if row.Asset_ID == ID: row.Processed = 'Y' rows.updateRow(row) del row, rows print 'finished'
au = "Assets_Unprocessed" lstIds = [] # with... syntax automaticalyy deletes auRows, row with arcpy.SearchCursor(au) as auRows: for row in auRows: lstIds.append(auRows.Asset_ID) with arcpy.UpdateCursor("Assets") as aRows: for row in aRows: if row.Processed == "N" and row.Asset_ID in lstIds: row.Processed = "Y" arows.update(row)
au = "Assets_Unprocessed"
fld = "Asset_ID"
lstIds = []
auRows = arcpy.SearchCursor(au)
for row in auRows:
lstIds.append(auRows.Asset_ID)
del auRows
del row
try:
aRows = arcpy.UpdateCursor("Assets")
for row in aRows:
if row.Processed == "N" and row.Asset_ID in lstIds:
row.Processed = "Y"
aRows.update(row)
except Exception as e:
print e.message
#do whatever
del aRows
del row
Greg,
Thanks for the input, I see how that could resolve my issue. I tried running that SearchCursor section of code you supplied, but an error was returned:
Runtime error <type 'exceptions.AttributeError'>: 'Cursor' object has no attribute '__exit__'
I am unfamiliar with the with...as statement so I'm not sure what is missing or needed here. I understand the process of building a list of Asset_ID's from Assets_Unprocessed then searching for records in Assets with those Asset_ID's, but it seems I'm having difficulty in first building that list with the SearchCursor and the use of the with...as statement.
au = "Assets_Unprocessed" lstIds = [] fld = "Asset_ID" auRows = arcpy.SearchCursor(au) for row in auRows: lstIds.append(auRows.Asset_ID)
table = 'assets_unprocessed' assetIDList = [] rows = arcpy.SearchCursor(table) for row in rows: assetIDList.append(row.Asset_ID) del row, rows table2 = 'assets' for ID in assetIDList: rows = arcpy.UpdateCursor(table2) for row in rows: if row.Asset_ID == ID: row.Processed = 'Y' rows.updateRow(row) del row, rows print 'finished'
The latest reply mentioned using a SearchCursor without the with...as statement, but I cannot get that to work either (error returns 'Cursor' object has no attribute 'Asset_ID' when I run the SearchCursor code: