Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Running a for loop over an empty cursor

$
0
0
ArcStandard 10.1

I have the following snippet in my script (with an intentionally empty cursor via where-clause):

Code:

271    rows = arcpy.da.SearchCursor(fc, Fields, "1=2")
272    arcpy.AddMessage(str(rows))
273    arcpy.AddMessage("Before")
274    for row in rows:
275        arcpy.AddMessage("In")

When I run it I get this:

Code:

Running script UpDownTest...
<da.SearchCursor object at 0x1758E700>
Before

Traceback (most recent call last):
  File "C:\Projects\UpstreamDownstream\UpDownStorm.py", line 274, in <module>
    for row in rows:
RuntimeError: A column was specified that does not exist.

Failed to execute (UpDownTest).

I'd thought before I started debugging that maybe I had a field name misspelled, but from printing the cursor I can see that an object is returned (though we know it's an empty cursor), and I can see I'm printing text after the cursor is created. Thus it seems like the error really is in the for loop. I can't figure out what's wrong here. Shouldn't the for loop just be passed over? Any suggestions?

Viewing all articles
Browse latest Browse all 2485

Trending Articles