arcpy.CalculateField_management(outCrash, "Segment_Code", !Segment_Code!.ljust(!Segment_Code!,6,0), "PYTHON")
Solved! Go to Solution.
Sorry to be a pest with this simple task, but still not working. Appears that is is treating the expression as the field.......confused.
It now returns the following error:
ERROR 000728: Field str(!Segment_Code!).zfill(6) does not exist within table
Failed to execute (CalculateField).
str(!Segment_Code!).zfill(6)
Calculator Expression:str(!Segment_Code!).zfill(6)
exp = str(!Segment_Code!).zfill(6) arcpy.CalculateField_management(outCrash, exp, "PYTHON")
exp = "str(!Segment_Code!).zfill(6)" arcpy.CalculateField_management(outCrash, exp, "PYTHON")
I think you just need quotes:exp = "str(!Segment_Code!).zfill(6)" arcpy.CalculateField_management(outCrash, exp, "PYTHON")
Sorry to be a pest with this simple task, but still not working. Appears that is is treating the expression as the field.......confused.
It now returns the following error:
ERROR 000728: Field str(!Segment_Code!).zfill(6) does not exist within table
Failed to execute (CalculateField).
You are using the wrong syntax. Check your tool documentation here. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000
The expression is the third variable passed to the tool, the field is the second.
I think you just need quotes:exp = "str(!Segment_Code!).zfill(6)" arcpy.CalculateField_management(outCrash, exp, "PYTHON")
Thanks for the suggestions Darren. The script now runs, but is not adding the 0's to the left side of the Segment_Code values. Any gotchas that I'm missing here?
Michael