Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In a shapefile, I have Field named Elevation with a text field containing integer ranges stored as strings:

1 - 2
3 - 6
2 - 3
8.5 - 12
11 - 12

I need to categorize it using rule that
if Elevation < 1 then Index = 0.3 ,if Elevation = 2 - 3 Index = 0.6, if Elevation > 3 Index = 1

I use this code :

def Reclass( Elevation ):
    r_min, r_max = (float(s.strip()) for s in Elevation.split('-'))
    if r_min < 1 and r_max < 1:
        return 0.333
    elif r_min >= 1 and r_max >= 1 and r_min <= 3 and r_max <= 3:
        return 0.666
    elif r_min > 3 and r_max > 3:
        return 1
    elif r_min <= 3 and r_max > 3:
        return 1
        return 999

error log :

General error executing calculator.
ERROR 999999: Error executing function.
Expected ')'
Failed to execute (CalculateField).
Failed at Mon Feb 10 10:31:00 2014 (Elapsed Time: 0,01 seconds)

Shape :

If I run that code in python window it runs perfectly but gets error in field calculator. how to fix that code in field calculator based on error log?

share|improve this question
I don't think strip is the function you want there – Nathan W Feb 10 '14 at 6:13
strip is the function I need, It's work like I Want. Thank You – Rikudo Pain Feb 10 '14 at 7:15
up vote 3 down vote accepted

Do not use print statements in the code block. print expects there to be a terminal to write to, and there is no such terminal inside of Calculate Field.

share|improve this answer
Still not working, can you give me sample code? – Rikudo Pain Feb 10 '14 at 2:26
@RikudoPain If this advice did not resolve it then can you edit your question to remove the print statement, confirm that the error is still the same, and include details of the precise settings you have on your Calculate Field dialog when this occurs, please? Knowing your Code Block is important but we also need to know that you are using the Python Parser and what you have set your expression to, and what format your table is stored in (e.g. file geodatabase, DBF, or something else). – PolyGeo Feb 10 '14 at 2:34
Update Question, including shapefile I want to change. – Rikudo Pain Feb 10 '14 at 2:42
"include details of the precise settings you have on your Calculate Field dialog when this occurs, please?" – PolyGeo Feb 10 '14 at 2:49
It's Already Working, the problem is, when I changed something in the script ArcGIS change the Type to VBS, I need to Change it again twice to Python in Field Calculator and It's DONE!! Thank You. – Rikudo Pain Feb 10 '14 at 7:14

Your Answer


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.