[GIS] Can anyone tell me why the field calculator is returning this error

arcgis-10.0arcpyerror-000539field-calculator

All I am trying to do is pull into a text field, a section of another text field via:

fieldB = !fieldA![some_index:other_index]

However I keep receiving the error below and I can't figure out why. My python syntax is correct and I have tried it in IDLE on an example string with the exact contents of a row in my feature class and it works fine.

I am using ArcGIS 10.0. The error is:

Executing: CalculateField AA_TCPs_Complete_060613 Cross_rd_1 !PopupInfo![5:10] PYTHON_9.3 #
Start Time: Fri Jun 07 13:31:03 2013
ERROR 000539: <type 'exceptions.SyntaxError'>:invalid syntax(<expression>, line 1)
Failed to execute (CalculateField).
Failed at Fri Jun 07 13:31:03 2013 (Elapsed Time: 0.00 seconds)

Best Answer

This syntax, that I just copied as a Python snippet from Geoprocessing | Results after running the Calculate Field tool, then worked fine from the Python window too. I used ArcGIS 10.1 SP1 but I would expect it to work at 10.0 equally well.

arcpy.CalculateField_management("Countries","TestField","!admin![0:3]","PYTHON_9.3","#")

If you are still having problems with this perhaps you can post (via an edit to your Question) exactly where you are using your syntax.

Related Question