3

I'm new to python and would like to use the label expression box with python to display only the odd or even integers from the field, [Frame_Number].

I was thinking something like

def FindLabel ( [Frame_Number] ):
  for num in [Frame_Number]:
     return num % 2
  return [Frame_Number] 

But I know that is incomplete.

6

Label expressions are similar to field calculator: you don't need to use a for loop as the expression is already applied to every feature. Also, you'll get an error with your code as per the help:

Field values are automatically cast to text strings. Therefore, if you wish to use a numeric value in an arithmetic operation, or when making a comparison, you will need to cast it back to a numeric data type. The examples below add two integer fields

Here it is displaying odd values:

def FindLabel([Frame_Number]):
  return [Frame_Number] if int([Frame_Number]) % 2 else "whatever you want here"

Alternatively, you can use a SQL expression in Label Manager to accomplish the same:

MOD(Frame_Number, 2) = 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.