Being the AML dinosaur that I am, I am just learning python and I need to convert a 2 digit numeric attribute in a table to a 2 digit zero-filled attribute in a script. Example 9 needs to be 09. Any help would be appreciated.
Tell me more
×
Geographic Information Systems Stack Exchange is a question and answer site for
cartographers, geographers and GIS professionals. It's 100% free, no registration required.
|
|
See the zfill() help in python.org or this stackoverflow post. As @artwork mentions, you must convert the value to string and make the calculation. You can use zfill() inside the cursor, or use as an expression in the Calculate Field tool. |
|||||||||
|
|
If you already have a value and you need to make it 2 digit value, have a look:
input->output: 2 -> 02, 20 -> 20 |
|||||||
|
|
This should do the trick (if using ArcGIS 10.1, for ArcGIS 10 you will have to use this update cursor):
Updated:
|
|||||||
|
