I have a point feature class for which I want to show labels based on a numeric "Field". My labels have to be rounded to the second decimal place and I need to have them padded with zeros. I know that I can manually modify it through the Layer Properties, but I need to write a script for that.
I have tried to run the following code, also based on other posts, but I end up with no labels at all:
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
layer = arcpy.mapping.ListLayers(mxd, "Layername")[0]
if layer.supports("LABELCLASSES"):
for lblClass in layer.labelClasses:
lblClass.className = "Field"
lblClass.expression = "Field".format("%.2f")
layer.showLabels = True
I wonder whether I have missed some steps. Thanks in advance for your help!