1

I'm doing some labeling and have my labels stacked using python by using the following: [field1] + 'n\' + [field2]. But I'd like to keep the label stacked and add parentheses to [field2] as well as ">= 1". I tried using the following with little success. So really I don't know how to combine everything correctly to get it to work properly.

def FindLabel ( [field1], [field2] ):
  if long([field2]) >= 1:
    return "[field1] + '\n' + [field2]"
  else:
    return [field1]

Ideally, I want my label to look like this:

Field1
(field2).

Got it to work besides the parentheses. I would still like to add them if possible.

def FindLabel ( [NAME], [Deaths] ): if long([Deaths]) >=1: return [NAME] + '\n' + [Deaths]

  • where does the >=1 fit in? is it a test or do you want it in the label – Ian Turton May 3 '16 at 14:44
  • I would like to label only features that have a value for field2 that is >=1. I wasn't really too sure where to insert that. – Bryden C May 3 '16 at 14:54
1

This should do the trick:

def FindLabel ( [field1], [field2] ):
  if long([field2]) >= 1:
    return [field1] + "\n" + "(" + [field2] + ")"
  else:
    return [field1]
  • 1
    Actually, you don't even need to use the Advanced code block: "{}\n({})".format([field1] , [field2]) if long([field2]) >= 1 else [field1] – Paul May 3 '16 at 15:46

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.