Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
share|improve this question
2  
do you have the python radio checked? –  Brad Nesom Jun 7 '13 at 18:44
1  
Is PopupInfo a text field? If it's numeric, I can see that causing the syntax error. –  Jason Scheirer Jun 7 '13 at 19:42
    
@ Brad: yes python radio is checked. –  Slw_Stdy_Sqz Jun 7 '13 at 19:52
2  
You said in your question that you are using 10.0. Why is the code error referencing PYTHON_9.3? Are you running this from ArcToolbox? Do you have any NULL data values, or data values < 11 characters long that may be causing it to bomb out? Can you post an image of your Field Calculator window? –  RyanDalton Jun 7 '13 at 21:04
1  
Another thought, do you have any quotes, exclamation points, or other special characters in your data that it might be getting confused with? –  RyanDalton Jun 7 '13 at 21:19

2 Answers 2

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.

share|improve this answer

I'm going to say that you can't access fieldA by index like that in Field Calculator. Might be wrong. Anyway, you could try it in VB: fieldB = Left([fieldA], 5), for example.

Or, try !fieldA[index1:index2]!

share|improve this answer
    
You would be wrong about your Python comment. The syntax works just fine for me in 10.0. –  RyanDalton Jun 7 '13 at 20:55
    
Well, that's why I said it might be wrong. In that case, why doesn't it work for the poster? –  recurvata Jun 7 '13 at 21:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.