I'm trying to update a python script to use the arcpy.da.SearchCursor instead of the legacy arcpy.SearchCursor. The cursor searches for duplicate values in a field.
I am getting an error:
Traceback messages below.
AttributeError: 'tuple' object has no attribute 'getValue'
There must be a syntax difference between the two cursors that I have wrong. Can anyone tell where I am going wrong?
#Constant Vars
dblayerprefix = "CityworksGIS_Test.DBO."
whydrant = dblayerprefix + "WHYDRANT"
#Parent
centralDB ="<YOUR DB CONNECTION>" #this variable used for replication
#Child
editDB ="Database Connections/DBO@CityworksGIS_Test.sde"
columnName = 'AssetID'
updateSql = "AssetID IS NULL"
noNullSql = "AssetID IS NOT NULL"
#old variable for arcpy.searchcursor
fieldascend = columnName + " A"
try:
#Set editor environment workspace
arcpy.env.workspace = 'Database Connections/DBO@CityworksGIS_Test.sde'
#Old cursor:
#rows = arcpy.SearchCursor('CityworksGIS_Test.dbo.WHYDRANT', noNullSql ,"","", fieldascend)
#New cursor
rows = arcpy.da.SearchCursor('CityworksGIS_Test.dbo.WHYDRANT', columnName, noNullSql, sql_clause=(None, 'ORDER BY ASSETID ASC'))
dupValuesList = [] #List for holding empty values
print 'Checking WHYDRANT for duplicate SampleID values'
i = -1
row = rows.next()
value = row.getValue(columnName)
for row in rows:
if row.getValue(columnName) != value:
value = row.getValue(columnName)
else:
dupValuesList.append(value)
#Check duplicates and create report
if len(dupValuesList) == 0:
print 'No duplicates found moving on'
del rows
del dupValuesList
else:
raise ValueError('Duplicate AssetID values found in WHYDRANT')
arcpy.da.SearchCursor()
as it appears you have updated that line, but the rest of the cursor lines are in the oldarcpy.SearchCursor()
format. – Midavalo♦ Oct 28 '16 at 17:37