Hot answers tagged


Please consider using an arcpy.da.SearchCursor: FieldNameDict = {} with arcpy.da.SearchCursor(dbf,[myfield,'AP_ZIP','AP_STATE','AP_CITY','AP_FULLADD','AP_BUILDIN']) as rows: for row in rows: FieldNameDict[row[0]] = row[1:] # everything but the first element As the row is a tuple that is returned you can use simple indexing [1:] to ...


I have not tested this but it is a one liner that uses dictionary comprehension, an arcpy.da.SearchCursor() and the indexing syntax from the answer by @MichaelStimson: FieldNameDict = {row[0]:[row[1:]] for row in arcpy.da.SearchCursor(dbf,[myfield,'AP_ZIP','AP_STATE','AP_CITY','AP_FULLADD','AP_BUILDIN'])}


Try something like: import arcpy fc = 'points1' fields = ['Field1','Field2','Field3','Result'] with arcpy.da.UpdateCursor(fc,fields) as cursor: for row in cursor: row[-1] = max(row[:-1]) cursor.updateRow(row) You might need to change max(row[:-1]). For example if you can have None values in some field, it will fail. Then try max([v for ...


I think this should work, intdict = {row[0]:row[1:] for row in arcpy.da.SearchCursor(interSectPts,['FID_ADDRSTAND','STREET', 'POINT_X','POINT_Y'])} with arcpy.da.UpdateCursor(addrLyr,['FID_ADDRSTAND','STREET','STARTX_2','STARTY_2', 'ENDX_2', 'ENDY_2','FROM_','TO_']) as cursor: for row in cursor: if (row[0] in intdict and intdict[row[0]][0] != ...


As already commented and your error message suggests, you are trying to write lists (=list data type) to a string field. Convert the list to a comma seperated string with join: row[1]=', '.join(diff[keyValue])


This should work, fields = ['R_ID', 'Type'] with arcpy.da.UpdateCursor(sorFeat, fields) as cursor: # Update R_ID field based on Type field. # Type is either WHITE, BLACK. for row in cursor: # Update Id field if Type is BLACK. if row[1] == 'BLACK': row[0] = autoIncrement() cursor.updateRow(row) You could ...

Only top voted, non community-wiki answers of a minimum length are eligible