<SPAN class="keyword token">import</SPAN> arcpy
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>
List_dissolve_fc <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>ListFeatureClasses<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"*Dissolve"</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># get a list of feature classes that end with "Dissolve"</SPAN>
fields <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="string token">"CO_NO"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"COUNTY_NAME"</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="comment token"># List of fields in test.gdb</SPAN>
<SPAN class="keyword token">for</SPAN> fc <SPAN class="keyword token">in</SPAN> List_dissolve_fc<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Loop through each feature class in the list</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>UpdateCursor<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">,</SPAN> fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN> <SPAN class="comment token"># Loop through each feature</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{[-17]}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>fc<SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># Update each feature in field [1] "COUNTY_NAME" using the name of the feature class without the last 17 characters. For example: walton_2019pin_Dissolve would be walton.</SPAN>
cursor<SPAN class="punctuation token">.</SPAN>updateRow<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">)</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>
Hello,
I need to loop through feature classes and in each feature class I need to update the field "COUNTY_NAME" with the name of the feature class. The problem is, that the name of the feature class is too long and I don't need to include the last 17 characters.
For example: "walton_2019pin_Dissolve" is the name of one feature class and I only want to use "walton" in the field names.
As you can see in the script this is written in line 12.
This method is not working.
How could I do this?
Thank you,
Natalia