I'm trying to calculate records in a text field to "01", keeping the preceding zero in tact using python script in ArcGis.
I can do this easily using the field calculator in ArcMap or the calculate field gp tool. But the script results in "1" instead of "01" and I can't figure out how to fix it.
arcpy.CalculateField_management("Table1","Field1","01","PYTHON","#")
-
Please do not include thanks in your posts here. It is considered unnecessary chit chat as per the Tour and help center.PolyGeo– PolyGeo ♦2016年05月20日 20:02:35 +00:00Commented May 20, 2016 at 20:02
2 Answers 2
Try putting your number "01"
into a second set of quotes "'01'"
(double-quote then single-quote or the other way around)
arcpy.CalculateField_management("Table1","Field1","'01'","PYTHON","#")
Try using the .zfill() function somewhere in your code. Input the length you are needing in the parentheses, 2 in your case. This will pad the text field with 0s
-
Could you please include an example of how to use
.zfill()
?2016年05月20日 20:48:32 +00:00Commented May 20, 2016 at 20:48 -
When i need to pad a field with 0's, say a ZIP code that is 00601, but displaying as 601. !ZIP!.zfill(5) would field calculate 2 0's in front, turning it into 00601Maksim– Maksim2016年05月20日 20:57:47 +00:00Commented May 20, 2016 at 20:57
Explore related questions
See similar questions with these tags.