Label Expression Example using Python will not give "expected" result

641
0
06-20-2012 07:36 PM
GraemeBrowning
Occasional Contributor III
The code below is given as an Example of the new Python parser for Label Expression in its documentation.

However, it looks like, and I think I've read somewhere, that all values get passed into the FindLabel expression as strings because when you run it against World Cities they all draw in large red letters.

def FindLabel ( [NAME], [POPULATION] ):
    if [POPULATION] >= 250000:
        return "<CLR red='255'><FNT size = '14'>" + [NAME] + "</FNT></CLR>"
    else:
        return [NAME]


Change the expression to the following (i.e. cast the POPULATION field as int) and you then get the expected result.

def FindLabel ( [NAME], [POPULATION] ):
    if int([POPULATION]) >= 250000:
        return "<CLR red='255'><FNT size = '14'>" + [NAME] + "</FNT></CLR>"
    else:
        return [NAME]


Can the code examples, particularly any that involve number comparisons or manipulations, be reviewed, please?
Tags (2)
0 Kudos
0 Replies