This question already has an answer here:
ERROR 000539: Error running expression: expression : name 'expression' is not definedFailed to execute (CalculateField).
The script is:
import arcpy, sys, array, time, datetime#Get feature datasetinws = arcpy.GetParameterAsText(0)#Set geoprocessing environmentsarcpy.env.workspace = inwsarcpy.env.overwriteOutput = True#Iterate through the list of feature classesfcList = arcpy.ListFeatureClasses()for fc in fcList: print str("processing" + fc)#Define field and expressionfield = "SID"expression = str(fc[:5])#Create a new field name and expressionarcpy.AddField_management(fc, field, "TEXT")arcpy.CalculateField_management(fc, field, "expression", "PYTHON")does anyone know what is going on here?Thanks!
أكثر...
- Why is arcpy.CalculateField_management() writing 1899-12-30 00:00:00 instead of expected date? 1 answer
ERROR 000539: Error running expression: expression : name 'expression' is not definedFailed to execute (CalculateField).
The script is:
import arcpy, sys, array, time, datetime#Get feature datasetinws = arcpy.GetParameterAsText(0)#Set geoprocessing environmentsarcpy.env.workspace = inwsarcpy.env.overwriteOutput = True#Iterate through the list of feature classesfcList = arcpy.ListFeatureClasses()for fc in fcList: print str("processing" + fc)#Define field and expressionfield = "SID"expression = str(fc[:5])#Create a new field name and expressionarcpy.AddField_management(fc, field, "TEXT")arcpy.CalculateField_management(fc, field, "expression", "PYTHON")does anyone know what is going on here?Thanks!
أكثر...