AnsweredAssumed Answered

Field Calculator convert text to integer then populate new field with sum

Question asked by SageRhys on Apr 30, 2015
Latest reply on Apr 30, 2015 by curtvprice

I have a .dbf with about 50 text fields containing numerals, I would like to convert those to integers and then sum them all in a new double field I created, is there an easy field calculation that could do this. I have working code but wanted to see other peoples examples/thoughts.

Pre-Logic Script Code:

def addition(*args):
  my_sum = 0
   for i in args:
  my_sum += int(i)
   return my_sum

prior2_3 = (my new field):

addition( !Hits_07_21!, !Hits_07_22!, !Hits_07_23!, !Hits_07_24!, !Hits_07_25!, !Hits_07_26!, !Hits_07_27!, !Hits_07_28!, !Hits_07_29!, !Hits_07_30!, !Hits_07_31!, !Hits_08_01!, !Hits_08_02!, !Hits_08_03!, !Hits_08_04!, !Hits_08_05!, !Hits_08_06!, !Hits_08_07!, !Hits_08_08!, !Hits_08_09!, !Hits_08_10!, !Hits_08_11!, !Hits_08_12!, !Hits_08_13!, !Hits_08_14!, !Hits_08_15!, !Hits_08_16!, !Hits_08_17!, !Hits_08_18!, !Hits_08_19!, !Hits_08_20!, !Hits_08_21!, !Hits_08_22!, !Hits_08_23!, !Hits_08_24!, !Hits_08_25!, !Hits_08_26!, !Hits_10_08!, !Hits_10_09!, !Hits_10_10!, !Hits_10_11!, !Hits_10_13!, !Hits_10_14!, !Hits_10_15!, !Hits_10_16!, !Hits_10_17!, !Hits_10_18!, !Hits_10_19!, !Hits_10_20!, !Hits_10_21!, !Hits_10_22!, !Hits_10_23!, !Hits_10_24!, !Hits_10_25!, !Hits_10_26!, !Hits_10_27!, !Hits_10_28!, !Hits_10_29!, !Hits_11_02!, !Hits_11_03!, !Hits_11_04!, !Hits_11_05!, !Hits_11_06!, !Hits_11_07!, !Hits_11_08!, !Hits_11_09!, !Hits_11_10!, !Hits_11_11!, !Hits_11_12!, !Hits_11_13!, !Hits_12_01!, !Hits_12_02!, !Hits_12_03!, !Hits_12_10!, !Hits_12_11!, !Hits_12_13!, !Hits_12_14!, !Hits_12_15!, !Hits_12_16!, !Hits_12_17!, !Hits_12_18!, !Hits_12_19!, !Hits_12_20!, !Hits_12_21!, !Hits_12_23!, !Hits_12_24!, !Hits_12_25!, !Hits_12_26!, !Hits_12_27!, !Hits_12_28!, !Hits_12_29!, !Hits_12_30!, !Hits_12_31!, !Hits_01_01!, !Hits_01_02!, !Hits_01_03!, !Hits_01_04!, !Hits_01_05!, !Hits_01_06!, !Hits_01_07!, !Hits_01_08!, !Hits_01_11!, !Hits_01_13!, !Hits_01_15!, !Hits_01_16!, !Hits_01_17!, !Hits_01_19!, !Hits_01_20!, !Hits_01_21!, !Hits_01_22!, !Hits_01_23!, !Hits_01_24!, !Hits_01_25!, !Hits_01_26!, !Hits_01_27!, !Hits_01_28!, !Hits_01_29!, !Hits_01_30!, !Hits_01_31!, !Hits_02_01!, !Hits_02_02!, !Hits_02_03!, !Hits_04_29!)