stsnider

Extract string in field calculator using python

Discussion created by stsnider on Dec 2, 2011
Latest reply on Dec 3, 2011 by stsnider
I'd like to use python in the field calculator to extract a string.  Basically the UTM North and East coordinates are in the same field and I'd like to parse them out.  An example of a field value is "North: 4479928.51 East: 290941.79".  When I run this very simple function in python, it works fine:
>>> def utmn(inValue):
utmn_start = inValue.find(":") + 2
utmn_stop = inValue.find("East") -1
return inValue[utmn_start:utmn_stop]
>>> utmn(field)
'4479928.51'

However, when I try to run it in the ArcGIS field calculator, i get an error message that the row contains a bad value.  None of the rows are null or contain text that is not in this format.  Here's what I put in the field calculator.  MERIDIAN_NAME_TEXT is the name of the field from which I am extracting the string.  UTM_North is the name of the input field.

Pre-Logic Script Code:
def utmn(inValue):
  utmn_start = inValue.find(":") + 2
  utmn_stop = inValue.find("East") -1
  return inValue[utmn_start:utmn_stop]

UTM_North =
utmn(!MERIDIAN_NAME_TEXT!)

Outcomes