1

I have 13 fields I need to Label all in one Label. But I dont want to label values with zero. Need to have Label before each field example (Field is (C_B) and need to read C&B, 2). Here is what i have so far but not sure if this is correct.

def findlabel ([VF_CL], [C_B], [VF_C_R], [VL_C_R_Unp], [MH_F_C], [MH_F_C_Unp], [Reset_MH_F], [Reset_MH_1], [RtoG], [RtoG_Unpav], [Voids], [Joints],[Drop]):
    # Set up the Headers
    Label = "VF CL " + [VF_CL], "C&B " + [C_B], "VF C/R " + [VF_C_R], + "  (not sure if this is correct)
    # Loop through Fields
    flds = [[VF_CL], [C_B], [VF_C_R], [VL_C_R_Unp], [MH_F_C], [MH_F_C_Unp], [Reset_MH_F], [Reset_MH_1], [RtoG], [RtoG_Unpav], [Voids], [Joints],[Drop]]
    for fld in flds:
        if (fld)>0:
            label =
        else:
            return None
    return Findlabel
1

Here's one way to do it. I haven't figured out how to do it in a loop to simplify it, unfortunately

def findlabel ([VF_CL], [C_B], [VF_C_R], [VL_C_R_Unp], [MH_F_C], [MH_F_C_Unp], [Reset_MH_F], [Reset_MH_1], [RtoG], [RtoG_Unpav], [Voids], [Joints],[Drop]):
  if float([VF_CL]) > 0:
    Label = "VF CL, " + [VF_CL] + " "
  if float([C_B]) > 0:
    Label += "C&B, " + [C_B] + " "
  if float([VF_C_R]) > 0:
    Label += "VF C/R, " + [VF_C_R] + " "
  #
  # rest of the fields
  #
  return Label
  • #def only works when i use if float([VF_VL]) >=0: for the 1st line not sure why? – Gonzo Jun 27 '16 at 19:23
1
# assuming your final product is string concatenated with all the values formatted like stated
value1 = 1
value2 = 1
flds = [['fieldstr1',value1],['fieldstr2',value2]]
def make_label(flds):
    total_label = ''
    for row in flds:
        if row[1] > 0:
            label = '%s,%s' % (row[0],row[1])
            total_label += label + ' '
    return total_label[:-1]
print make_label(flds)

output : 'fieldstr1,1 fieldstr2,1'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.