I have some unexpected behaviour in an
UpdateCursor. I'm iterating over quite a large dataset, and I've found that Python freaks out less if I break up the iteration into chunks:
env.workspace = r"ROADS.gdb" arcpy.MakeFeatureLayer_management("JUNCTIONS", "jn_layer") for i in range(-70000, 1500000, 10000): strFilter = "UFI >= " + str(i) + " AND UFI < " + str(i+10000) print strFilter with arcpy.da.UpdateCursor("jn_layer", ["OID@","UFI"], strFilter) as upCursor: for rowInt in upCursor: # do stuff
I would expect this to create a new cursor for each iteration with different filters, as per the
UFI >= -70000 AND UFI < -60000 UFI >= -60000 AND UFI < -50000 UFI >= -50000 AND UFI < -40000 ...etc
The problem is the first iteration works as expected, but each subsequent iteration of
i returns no rows - it spits out each subsequent filter value but does nothing inside the
with loop. Once it finishes, if I change the initial value:
for i in range(-60000, 1500000, 10000):
then it processes the first 10000 values (which were ignored before), but again the rest of the iterations of the
with loop return no values. It feels like it's keeping the first filter on
jn_layer and trying to apply the second filter to that filtered set, which of course returns no rows since there's no overlap between the ranges.
Is this the expected behaviour? I would have thought creating a cursor on a layer would only filter the layer for as long as the cursor exists, and the
with keyword should be destroying the cursor before the filter changes...? Any advice would be most welcome.