In ArcGIS Pro 2.2.4, I have a file geodatabase feature table where the ZIP code was imported as a long named "ZIP." I need it to be a string to 1) preserve leading zeroes and 2) join with another table on the ZIP field.
I opened the attribute table and added a new field called "ZIPText" of type String. I open Calculate Field and using Python 3, try to define ZIPText as !ZIP!.asString()
The expression validates, but when I run it, I get
ERROR 000539 File "<expression>", line 1
94501.asString()
with the carat pointing at the "g" at the end of asString.
I've tried other expressions, but my Python is of the "google and try it variety" and Google's out of options.
Any ideas?
Solved! Go to Solution.
python parser...
str(!ZIP!)
and make sure the destination field is indeed text...
python parser...
str(!ZIP!)
and make sure the destination field is indeed text...
Ha! I knew it would be something that simple. It works perfectly. Thank you sir.
Since ZIPs are currently stored as long, there won't be any leading zeroes to preserve. If you want to create them, you can use Python string formatting:
"{:0>5}".format(!ZIP!)
Thank you! I had intended to add the leading zeroes manually since there aren't that many, but this is a much better way.