I'm trying to write a python script to label multiple columns of an attribute table based on certain parameters. For example, if Benzene is over 79, I want it to be red. I've gotten that part fine, but for some reason I can't get the labels to stack, it only displays the first one the meets the if/then statement. Here's what I have so far:
def FindLabel ( [NAME], [Acetone], [Benzene], [1_3_Butadi] ):
if int( [Benzene] ) > 79:
message = "<bol>" "<clr red = '255'>"+"Benzene:" + [Benzene] + "</clr>" + "</bol>"+ "\n"
return message + "\n"
if int( [Benzene] ) > 0:
message = "<bol>" "<clr green = '255'>"+"Benzene:" + [Benzene] + "</clr>" + "</bol>"+ "\n"
return message + "\n"
if int( [Acetone] ) > 0:
message = "<bol>" "<clr green = '255'>"+"Acetone:" + [Acetone] + "</clr>" + "</bol>" + "\n"
return message + "\n"
if int( [1_3_Butadi] ) > 0:
message = "<bol>" "<clr green = '255'>"+"1,3-Butadiene:" + [1_3_Butadi] + "</clr>" + "</bol>"+ "\n"
return message + "\n"
I essentially want it to display like this
Benzene: 79
Acetone: 12
1,3-Butadiene:13
I tried using:
return "{0}\n{1}".format([Acetone], [Benzene], [1_3_Butadi])That allowed me to stack the labels but then I lost the formatting I wanted.