# Small issue with field calculator

What am I doing wrong in this field calculator logic?

Pre-logic

``````def re_score(elev_t,f2, contour):
f2=contour
if elev_t.endswith('.5'):
f2 = "Midi"
return f2
``````

Expression for field "Contourtyp"

`````` re_score(!Elev_t!,f2,!Contourtyp!)
``````

I just want to rename the contour type where the contours are at half meter intervals. The 'Elev_T' is a text column with all the elevations (converted to text as I couldn't think of a way to do it with numerical elevation data which has .25, .5, 75 and 1m intervals). I want all .5 called 'midi' and .25/.75 remain as 'minor' and 1m remains as 'basic'

Executing (Calculate Field (3)): CalculateField 328000_8123000 Contourtyp " re_score(!Elev_t!,f2,!Contourtyp!)" PYTHON_9.3 "def re_score(elev_t,f2, contour):\n f2=contour\n if elev_t.endswith('.5'):\n f2 = "Midi"\n return f2" Start Time: Thu Apr 12 17:10:40 2012 ERROR 000539: : unexpected indent (, line 1) Failed to execute (Calculate Field (3)). Failed at Thu Apr 12 17:10:40 2012 (Elapsed Time: 0.00 seconds)

I have tried different indentation and no luck...

Thanks

-

Try:

``````def re_score(elev_t, contour):
if elev_t.endswith('.5'):
return "Midi"
else:
return contour
``````

and then:
Countourtyp =

``````re_score(!Elev_t!, !Contourtyp!)
``````
-
Brilliant! thanks...didn't know that we could just return a value and not have it as f2=value... :-) –  GeorgeC Apr 12 '12 at 22:44