I've seen many similar questions but somehow never found an answer that I can understand and apply to my problem. I have a layer with Census tracts. I have a layer with parcels. I need to iterate through each tract, select the parcels falling inside, do some things to the parcels (for the sake of testing, I'm trying to copy the parcels in each tract into a new feature class named with the tract number), then repeat for the next tract. The loop works, insofar as it runs through each tract and creates a new feature class that is named with the tract number. But rather than each feature class containing only the parcels falling inside the respective tract, each resulting feature class includes all parcels falling inside all tracts. I'm clearly missing some important construct in my loop. Please help!
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"tracts"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TRACT_NUMBER"</SPAN><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>
arcpy<SPAN class="punctuation token">.</SPAN>SelectLayerByLocation_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"parcels"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"HAVE_THEIR_CENTER_IN"</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"tracts"</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>CopyFeatures_management<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"parcels"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"parcels_"</SPAN><SPAN class="operator token">+</SPAN><SPAN class="string token">"{}"</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>