1

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","#")
Midavalo
30k11 gold badges53 silver badges108 bronze badges
asked May 20, 2016 at 19:26
1
  • Please do not include thanks in your posts here. It is considered unnecessary chit chat as per the Tour and help center. Commented May 20, 2016 at 20:02

2 Answers 2

1

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","#")
answered May 20, 2016 at 20:41
1

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

answered May 20, 2016 at 20:23
2
  • Could you please include an example of how to use .zfill()? Commented 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 00601 Commented May 20, 2016 at 20:57

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.