Updating Symbology on Layer using ArcPy?

Discussion created by deleted-user-Bzr4vpYlGUla on Jul 30, 2019

I've been trying to update the symbology of a layer on my Python script. The layer that is to be updated shows the percentage of an age range in each region across a county. I have created a test layer (as suggested on GraduatedColorsSymbology ArcPy Website) which copies the symbology of the test layer to the layer I am editing. I have set the symbology of this test layer to use the same dataset as the new layer, but uses a different age range (0 - 16 years).

This worked as expected, so now I want to update the Symbology to use a different age range (65 and Over) using the GraduatedColorsSymbology ArcPy page.

Below is my code:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\MyMaps\Ages.mxd")   
= arcpy.mapping.ListDataFrames(mxd)[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "Age_Range")[0]
sourceLayer = arcpy.mapping.Layer(r"C:\MyLayers\TEST_LAYER.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)    

if updateLayer.symbologyType == "GRADUATED_COLORS":       
.symbology.valueField = "PCT_65_OVR"       
.symbology.numClasses = 5   

When I execute this code, I get the error ValueError: PCT_65_OVR. I made sure that the attribute name in the code is the same as what is on the symbology layer, so not sure why I am getting this code.