I'm currently trying to update the fields of a shapefile, with a list I've compiled outside of the arcpy environment. Trying both UpdateCursor which I can't seem to get to work, and FieldCalculator. FieldCalculator just updates it with "P[2]"
photoname = []
for p in shp_list:
name = p[2]
photoname.append(name)
# arcpy.CalculateField_management(out_shapefile,"PhotoName","'p[2]'","PYTHON_9.3")
I've also tried:
updt_cursor = arcpy.da.UpdateCursor(out_shapefile, fields)
for row in updt_cursor:
val = str(row[0])
for p in shp_list:
if val in p:
row[2] = p_name
updt_cursor.updateRow(row)
And UpdateCursor is blank.
I know I could create a .txt from the list, then update the fields with the line in the .txt file with InsertCursor, but I feel like there should be a more efficient way to do this. For context, I'm creating point shapefiles of the X/Y from the exif data, and want to fill in the corresponding image name.
del updt_cusorat the end, but the better practice is to use awithblock so it gets done automatically. See the examples: pro.arcgis.com/en/pro-app/arcpy/data-access/…if val in p:condition is never met-- if it was, you would get an exception because you never definedp_name. Do some standard debugging here: print outshp_listto make sure it contains what you expect, printvalfrom within the main loop, printpfrom within the inner loop, etc.shp_listand some of the correspondingvalvalues?