just wondering if anyone else is having issues with the field calculator in ArcGIS 10 SP3. In the following code I do a pretty simple field calculation with a variable (an array) as one of the parameters in the expression.
exp1 = "Feature = 16"
rows = arcpy.SearchCursor("ObservationMaster", exp1)
li = []
for row in rows:
ObsID = int(row.getValue("ObsID"))
li.insert(len(li), ObsID)
if li != []:
codeblock = """def chStat(stat, ID, li):
if int(ID) in li:
return 5
else:
return int(stat)"""
exp = """chStat(str(!ManagementStatus!), str(!ObsID!), li)"""
arcpy.CalculateField_management("ObservationDetail", "ManagementStatus", exp, "PYTHON", codeblock)
When I run it through IDLE (Python 2.6.5), there are no problems and it runs successfully. However, if I create a script in a toolbox in ArcCatalog/ArcMap using this same code, I get the following error:
<class 'arcgisscripting.ExecuteError'>: ERROR 000539: Error running expression: chStat(str(1), str(1), li) <type 'exceptions.NameError'>: name 'li' is not defined
Failed to execute (CalculateField).
I know this is because it is not treating "li" as a variable, but it does when I run it in IDLE. Has anyone had this same problem and does anyone know a solution to get this working. I really need this script to run via ArcMap.
Thanks in advance
exp
andcodeblock
variables are commented out with the multi-line comment