Calculating Field

3989
4
Jump to solution
01-22-2015 01:25 PM
MichelleCouden
Occasional Contributor

I have 2 fields I need to concatenate together and add zeros and a hypen.

For Example: 0001-02

In the past this code worked :

"00{0}-0{1}".format(int(!ACONTROL!)),int(!ASECTION!))

 

This time I am getting an error of :

SyntaxError: unexpected EOF while parsing(<string>, line 1)

 

My empty field I created is a text. The AControl field is a double and the ASection field is a double.

 

Why is my code not working this time? What have I changed? Please help. THanks!

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

If you want to make it a little more robust, but slightly more complex you could use:

"{0}-{1}".format("{0}".format(int(!ACONTROL!)).zfill(4),"{0}".format(int(!ASECTION!)).zfill(2))

This will yield:

result2.png

as the first suggestion will yield:

result1.png

View solution in original post

4 Replies
XanderBakker
Esri Esteemed Contributor

It is not something that is missing... you have a parenthesis too much:

"00{0}-0{1}".format(int(!ACONTROL!),int(!ASECTION!))

0 Kudos
XanderBakker
Esri Esteemed Contributor

If you want to make it a little more robust, but slightly more complex you could use:

"{0}-{1}".format("{0}".format(int(!ACONTROL!)).zfill(4),"{0}".format(int(!ASECTION!)).zfill(2))

This will yield:

result2.png

as the first suggestion will yield:

result1.png

MichelleCouden
Occasional Contributor

Thank You xander for your help. The second code worked great!!

0 Kudos
XanderBakker
Esri Esteemed Contributor

Glad it worked!

0 Kudos