I am trying to calculate values for a field in a python script, but keep getting an error that I don't understand:
ExecuteError: ERROR 000539: Error running expression: Fron000000F1
Traceback (most recent call last):
File "<expression>", line 1, in <module>
NameError: name 'Fron000000F1' is not defined
Failed to execute (CalculateField).
I can't figure out where the name 'Fron000000F1' is coming from to try and track this problem. I have tested the expression in arcmap using the field calculator with no problems. What is wrong? Code is below:
import arcpy, os, csv
arcpy.env.overwriteOutput = True
out_fc_pm = r'C:\temp\temp.gdb\SignDetect__SOL680_DD_with_PM'
def calc_id(pm,pict_fld):
import re
pm_patt = re.compile('\d*\.*\d*')
pm_match = re.findall(pm_patt,pm[5:])[0]
pm = pm_match.replace('.','')
pm_final = pm.zfill(6)
dir_patt = re.compile('[A-Z]\d*')
dir_match = re.findall(dir_patt,pict_fld)[0]
id = pict_fld[:5]+pm_final+dir_match
if id[-1:].isdigit():
return id
else:
return id+'1'
arcpy.AddField_management(out_fc_pm,'OSMI_ID','TEXT')
arcpy.CalculateField_management(out_fc_pm,'OSMI_ID',calc_id('!POSTMILE!','!Front!'),'PYTHON_9.3')