Hello!
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.
Problem:
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.
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token"># script to change fc name using a dictionary</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> r<SPAN class="string token">"D:\APRX_MXDS\USA_Parcels_2019_Project\test.gdb"</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>overwriteOutput <SPAN class="operator token">=</SPAN> <SPAN class="token boolean">True</SPAN>
fc_list <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"points*"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># list of fc that end with points</SPAN>
<SPAN class="comment token"># dictionary</SPAN>
county_codes <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="number token">14</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Bradford"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">15</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Brevard"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="number token">16</SPAN> <SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Broward"</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> fc_list<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># loop through the feature classes</SPAN>
key <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{[1:3]}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">.</SPAN>name<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># let the second and third characters in the fc name be the key</SPAN>
<SPAN class="keyword token">if</SPAN> key <SPAN class="keyword token">in</SPAN> county_codes<SPAN class="punctuation token">:</SPAN>
fc <SPAN class="operator token">=</SPAN> county_codes<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>key<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># assign the value in the dictionary as the new feature class name</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>thank you!