AnsweredAssumed Answered

Using Python Dictionaries to Change Feature Class Names

Question asked by NatiNati1186 on Apr 30, 2020
Latest reply on May 6, 2020 by NatiNati1186


I recently posted a question about python dictionaries and here I am again struggling with them..

I am now trying to use them to change feature class names.



I have a list of 77 feature classes and I need to change their names from codes to names using a python dictionary.


For example:

Feature class name: T14_single_points

New name that I need: Alachua


I am not getting any errors when running this code but I am not getting any results either.

import arcpy

# script to change fc name using a dictionary

arcpy.env.workspace = r"D:\APRX_MXDS\USA_Parcels_2019_Project\test.gdb"
arcpy.env.overwriteOutput = True

fc_list = arcpy.ListFeatureClasses("points*") # list of fc that end with points

# dictionary
county_codes = {14 : "Bradford", 15 : "Brevard", 16 : "Broward"}

for fc in fc_list: # loop through the feature classes
    key = "{[1:3]}".format( # let the second and third characters in the fc name be the key
    if key in county_codes:
        fc = county_codes.get(key) # assign the value in the dictionary as the new feature class name


thank you!