I'm writing a python program where I need to field calculate using a python function. The function takes two strings; one used for an if statement and the other to become an integer complete a simple addition equation. It then returns a string of that integer.
I've completed the calculation on the table in ArcCatalog and it works, but in Python it doesn't and gives me the following error:
ExecuteError: Failed to execute. Parameters are not valid. ERROR 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 1) Failed to execute (CalculateField).
My function:
def yearStr(age, date):
if age == 'BC':
start = str((int(date) * (-1)) + 2251)
if age == 'AD':
start = str(int(date) + 2251)
return start
Called using this:
yearStr(!Period!, !Year!)
In Python it looks like this:
arcpy.CalculateField_management(transp_table,"Start_Time","yearStr(!Period!, !Year!)","PYTHON_9.3","def yearStr(age, date):/n if age == 'BC':/n start = str((int(date) * (-1)) + 2251)/n if age == 'AD':/n start = str(int(date) + 2251)/n return start")
I would appreciate any help! Have tried adding ' ' around field names and variables