AnsweredAssumed Answered

Python labelclasses expression help

Question asked by GEOlson86 on Jun 11, 2015
Latest reply on Jun 22, 2015 by jdkelly

I'm working with many shapefiles that all need to be symbolized and labeled the same way.  I've gotten symbol layer matching to work, but I've having difficulty with the labels, particularly with the expression working.  My expressions works fine loading the text file from the layer properties window, but not through the Python console.  My expression uses the Advanced Python dialogue box.

Here is my code so far.  It's copied and pasted from the expression window and wrapped in triple quotes, but it does not end up labeling.  Is there a particular way to enter the expression?

 

mxd = arcpy.mapping.MapDocument("Current")# Define mxd to current file.

inputData0 = "AM_Bourbonnais_Pkwy_WB_LINE_Spring_2015"

mapLyr0 = arcpy.mapping.ListLayers(mxd, inputData0) [0]

lFunc = """def FindLabel ( [Speed] ):\n

  label = str(round(float([Speed]),0))\n

  if label[1] == '.':\n

    label = label[:1]\n

    label = label + " MPH"\n

    return label\n

  else:\n

    label = label[:2]\n

    label = label + " MPH"\n

    return label"""

 

mapLyr0.labelClasses[0].expression = lFunc

Outcomes