I'm trying to add a part of my filename into a field that i'd created, but it comes with the following error:
Traceback (most recent call last): File "Z:\04 - Temp\Charles\NDVI_tempo\NDVI_py3.tbx#Script_NDVIpy3.py", line 50, in File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 3019, in CalculateField raise e File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\management.py", line 3016, in CalculateField retval = convertArcObjectToPythonObject(gp.CalculateField_management(*gp_fixargs((in_table, field, expression, expression_type, code_block), True))) File "c:\program files\arcgis\pro\Resources\arcpy\arcpy\geoprocessing_base.py", line 506, in return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 000539: Error running expression: test Traceback (most recent call last): File "", line 1, in NameError: name 'test' is not defined
Failed to execute (CalculateField). Failed to execute (Script).
This is the script that i wrote:
intershp = 'Z:\\04 - Temp\\Charles\\NDVI_tempo\\NAL\\intershp.shp'
arcpy.AddField_management (intershp, "Data", "TEXT", "", "", "", "", "", "", "")
tiff_name = tiff.split("_")[0]
field_name = "{}".format(tiff_name[0:4])
arcpy.CalculateField_management (intershp, "Data", field_name, "", "")
intershp = r'Z:\04
- you need to raw string your parameter