In an ArcPro python script I have created a feature layers from a GDB feature class and made a selection.
field_values <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># Field names are identical between the source and the target</SPAN>
row_cnt <SPAN class="operator token">=</SPAN> int<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>GetCount_management<SPAN class="punctuation token">(</SPAN>selected_layer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
cnt <SPAN class="operator token">=</SPAN> <SPAN class="number token">0</SPAN>
<SPAN class="keyword token">with</SPAN> da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>selected_layer<SPAN class="punctuation token">,</SPAN> update_fields<SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> _cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> _row <SPAN class="keyword token">in</SPAN> _cursor<SPAN class="punctuation token">:</SPAN>
update_values <SPAN class="operator token">=</SPAN> _row<SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">:</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
_geo <SPAN class="operator token">=</SPAN> _row<SPAN class="punctuation token">[</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">for</SPAN> i <SPAN class="keyword token">in</SPAN> range<SPAN class="punctuation token">(</SPAN>len<SPAN class="punctuation token">(</SPAN>update_values<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
fld <SPAN class="operator token">=</SPAN> update_fields<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">if</SPAN> fld <SPAN class="operator token">not</SPAN> <SPAN class="keyword token">in</SPAN> field_values<SPAN class="punctuation token">:</SPAN>
field_values<SPAN class="punctuation token">[</SPAN>fld<SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN>update_values<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
field_values<SPAN class="punctuation token">[</SPAN>fld<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>update_values<SPAN class="punctuation token">[</SPAN>i<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># add this row to the excel table for visual comparison of source data to the final row</SPAN>
test_rows<SPAN class="punctuation token">.</SPAN>append<SPAN class="punctuation token">(</SPAN>update_values<SPAN class="punctuation token">)</SPAN>
cnt <SPAN class="operator token">+=</SPAN> <SPAN class="number token">1</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></SPAN><SPAN></SPAN></SPAN>The row count of the selected layer is 21, but when I increase the cnt variable by one each time through the cursor, the total number of lines is 167.
Has anyone experienced this issue with ArcPy for Pro? Do layer selections in Pro not work with da.Cursors?
I was thinking that a naming conflict between the feature class and the layer could be happening so I appended "_lyr" to the end of the layer name.