python script error- with GetParameterAsText [duplicate]

المشرف العام

Administrator
طاقم الإدارة
This question already has an answer here:


I have a seemingly simple code which iterates through a list of feature classes and calculates an ID field in the attribute table that is equal to the first 5 characters of feature class name. The script works fine if I hard code the workspace. As soon as I change it to "Get Parameter as Text" I receive this error:

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!



أكثر...
 
أعلى