Python Label Expression

6480
15
10-01-2013 12:36 PM
BartonGriesenauer
New Contributor II
I am trying to create one label expression that has two label options.  The first option will stack the parcel number on top of the lot number and the other option would stack the parcel number on top of deeded acreage.  The [LOTNUMBER] field, [PARCEL] field, are text fields the [DEEDACRES] is a double.  I have no python experience, did not think this expression would be this difficult to come up with.  I would appreciate any help.


def FindLabel ( [PARCEL] , [LOTNUMBER] , [DEEDACRES] 😞
  if long([LOTNUMBER]) >1:
    return "<CLR yellow='255'>" +  [PARCEL] + "</CLR>" + '\n' + [LOTNUMBER]
  else:
    return "<CLR yellow='255'>" +  [PARCEL] + "</CLR>" + '\n' + [DEEDACRES]
Tags (2)
15 Replies
MatthewDobson
Occasional Contributor
Or using 'not' ....

def FindLabel ( [PARCEL] , [LOTNUMBER] , [DEEDACRES] ):
  if not [LOTNUMBER]:
    return "<CLR yellow='255'>" + [PARCEL] + "</CLR>\n" + str([DEEDACRES])
  else:
    return "<CLR yellow='255'>" + [PARCEL] + "</CLR>\n" + [LOTNUMBER]
0 Kudos
BartonGriesenauer
New Contributor II
Thank you very much for your help that did it!
0 Kudos
Zeke
by
Regular Contributor III

Siran,

To label numbers divisible by 100, use the modulo operator. In the label expression advanced box, set the parser to Python. Then use a function like below:

def FindLabel(somefield):

    if somefield % 100 == 0: return somefield

if you want to label with a different field based on somefield:

def FindLabel(somefield, anotherfield):

    if somefield % 100 == 0: return anotherfield

0 Kudos
SiranErysian
New Contributor

this did not work:

I used 50% since I want to label every 50' contour

tried it without brackets around Contour also but it didn';t work.

0 Kudos
Zeke
by
Regular Contributor III

You're not using 50%. You're using modulo 50; the modulo operator is the % sign in Python. It's like regular division, except it gives you the remainder.

Primarily though, you need parentheses around the field name in the first line - def FindLabel([Contour]):

You also need to see whether the expression if [Contour] % 50 == 0: You left the 0 out above.

0 Kudos
SiranErysian
New Contributor

Thanks. I re do and be more careful next time....

0 Kudos