I need to change the way my labels are displayed in ArcMap using ArcPy. I want to replace underscores with spaces in label strings with using string.replace("_"," "). I have SHOWLABELS set to True, but I'm having trouble accessing the label values themselves in ArcPy. Looking in the LabelClass documentation, I can't find any method to print out or alter the label values.
city_layer = arcpy.mapping.ListLayers(mxd, "cities") countries_layer = arcpy.mapping.ListLayers(mxd, "countries") if city_layer.supports("SHOWLABELS"): city_layer.showLabels = True if countries_layer.supports("SHOWLABELS"): countries_layer.showLabels = True
Do you mean the layer name in the TOC, which some people loosely call label, or do you mean labels of features in the map. Labels of features are typically driven by data, either directly or through expressions. If some text in a field is being used to label a feature, and that text has the underscore, then updating the text is the way to go. If an expression is inserting the underscore, then modifying the expression is the way to go.