Having trouble here: I'm trying to use python to write selective label expressions. I have several concentrations and depending on its "_Ex" number I either want it labeled red, not red, or not labeled at all. I have started with just one trying to set it to red. when i put this into the lable expression it says line one Findlabel not defined.
Any help would be appreciated. -Acrain (Indentations are not showing up correctly here, but I don't think thats my problem)
def FindLabel ([cis12DCE] , [cis12DCE_Ex]):
if short ( [cis12DCE_Ex] ) = 1:
return "<clr red = "255">"+"cis-1,2-Dichloroethylene "+[cis12DCE]+"</clr>
else:
return "cis-1,2-Dichloroethylene "+[cis12DCE]
enter image description here
-
I edited my answer. See if that helps.Get Spatial– Get Spatial2013年05月06日 15:48:38 +00:00Commented May 6, 2013 at 15:48
3 Answers 3
I think there are a couple issues.
- You seem to be having a problem with indentations and extra spacing between your def line and your
if
statement. Theif
statement needs to be on the next line. - I think you are embedding a series of double quotes inside each other.
Edit - Change expression to double ==
sign, HT @Hotpepper
Edit 2 - I am including a screenshot of how the expression should be entered in the expression window. In addition, based on the error, I think you should simply try casting the field back to an integer int
instead of using short
, as I'm not sure that is supported.
For reference, here is the relevant ESRI Help document: Building Label Expressions
Try:
def FindLabel ([cis12DCE],[cis12DCE_Ex]):
if int([cis12DCE_Ex]) == 1:
return "<clr red = '255'>"+"cis-1,2-Dichloroethylene "+[cis12DCE]+"</clr>"
else:
return "cis-1,2-Dichloroethylene "+[cis12DCE]
enter image description here
-
I appreciate your help, I made your changes but am still getting an error. Is there a specific way to enter/copy the code into the parser?ACrain– ACrain2013年05月06日 15:31:59 +00:00Commented May 6, 2013 at 15:31
-
I have added the error to my main questionACrain– ACrain2013年05月06日 15:40:56 +00:00Commented May 6, 2013 at 15:40
-
Fantastic thank you soooo much. Works perfectly I can build off this. Thanks again you really helped me out. -AdamACrain– ACrain2013年05月06日 16:00:55 +00:00Commented May 6, 2013 at 16:00
-
Glad that I could help. I would appreciate it if you would mark this answer as accepted. This will help other people who are searching for something similar.Get Spatial– Get Spatial2013年05月06日 16:10:30 +00:00Commented May 6, 2013 at 16:10
-
@ACrain - Just wondering why you switched the accepted label to the other answer. I could understand if that was the only issue with the expression, but I thought there were a number of factors I helped you out with. Glad to help regardless, and hope you get your problem solved.Get Spatial– Get Spatial2013年05月06日 17:38:06 +00:00Commented May 6, 2013 at 17:38
It looks like your missing an equals sign in your if statement
if short ( [cis12DCE_Ex] ) = 1:
should be
if short ( [cis12DCE_Ex] ) == 1:
Try this:
def FindLabel ([cis12DCE],[cis12DCE_Ex]):
if int([cis12DCE_Ex]) == 1:
return "<clr red = '255'>"+"cis-1,2-Dichloroethylene "+str([cis12DCE])+"</clr>"
else:
return "cis-1,2-Dichloroethylene "+str([cis12DCE])