I am working on a toolset, and one of the inputs is a field of a shapefile. I have defined the field and I have used it in multiple functions, and it is working without any error.
The problem is that when I want to use the field in an expression in CalculateField, it does not recognize the defined field, but when I use the name of field (name in attribute table) it works.
I think that I make mistake in writing the code for the expression part.
import os, sys import arcpy from arcpy import env from arcpy.sa import * arcpy.CheckOutExtension("Spatial") ###### Define variables shapes = sys.argv outputfolder = sys.argv outputname = sys.argv field = sys.argv output = os.path.join(outputfolder,outputname) arcpy.AddMessage(shapes) arcpy.AddMessage(field) arcpy.AddMessage(output) shapes1=arcpy.AddField_management(shapes,'Classific','TEXT') shapes2=arcpy.CalculateField_management(shapes1,'Classific',"!Classific!.replace(!Classific!,field)", 'PYTHON3') Unionfield = arcpy.CalculateField_management(Unionfield, field, "field+ !FIRST_Clas!", 'PYTHON3') Unionfield = arcpy.CalculateField_management(Unionfield, field, "!Class!+ !FIRST_Clas!", 'PYTHON3')
Also, I have another question about adding the output of my toolset to the contents after each running.
When I run my toolset every time, the output does not appear in the contents, every time I have to import the output from outputfolder.