# Using search cursor with ArcPy and Spyder?

I recently installed ArcGIS 10.3.1 (previously had 10.1 installed) and I am trying to run a script in Spyder 2.7 that has always worked and getting the below error:

"Traceback (most recent call last):

File "<ipython-input-4-95832f8a9f6d>", line 1, in <module>
perimCur = arcpy.SearchCursor(subwatSubPath + subwatPerimsSub[i])

File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\__init__.py", line 1179, in SearchCursor
return gp.searchCursor(dataset, where_clause, spatial_reference, fields, sort_fields)

File "C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy\arcpy\geoprocessing\_base.py", line 359, in searchCursor
self._gp.SearchCursor(*gp_fixargs(args, True)))

RuntimeError: ERROR 999999: Error executing function."


I've tried reinstalling both ArcGIS and Spyder xy, but am still getting the same errors. After looking extensively online, I can't find a solution, although I suspect it may be a path issue. Can anyone help me identify the problem?

I don't know if this is related, but when I import from the spatial analyst module by calling from arcpy.sa import * I get a warning that states unable to detect undefined names.

• Please include a code snippet so that we know precisely what you have run to see those errors. – PolyGeo Nov 4 '15 at 2:36
• If you print out your SearchCursor input (subwatSubPath + subwatPerimsSub[i]), what do you get? Also, if you put the line print arcpy.Exists (subwatSubPath + subwatPerimsSub[i]) prior, does it print True (exists) or False? – Emil Brundage Nov 4 '15 at 3:18
• My code is: import arcpy, os from arcpy import env import arcpy.sa as sa from arcpy.sa import * import numpy as np subwatSubPath = u'C:\\Users\\Cameron\\Desktop\\pythonWorkspace\\subwat/subwat_sub30/' subwatPerimsSub = [i for i in os.listdir(subwatSubPath) if i.endswith('shp')] The subwatPerimSub call returns [u'subPerim1.shp', u'subPerim2.shp']. If I print arcpy.Exists (subwatSubPath + subwatPerimsSub[i]) it returns "True". – help.me Nov 4 '15 at 3:42
• @help.me, that's not what he meant by "include a code snippet". Please edit your post to include the code and format it as such (highlight the code and hit ctrl+k). – Tom Nov 10 '15 at 0:33

In your comment, you write that subwatSubPath is u'C:\\Users\\Cameron\\Desktop\\pythonWorkspace\\subwat/subwat_sub30/'. That's an odd-looking file path because of the changing slash directions. I would make them consistent (e.g., all \\, or just \ but prefacing the string with r to indicate it's raw and that the escape \ should be ignored, like r"c:\foo\bar"). Consider, also, instead of subwatSubPath + subwatPerimSub[i], doing:
mypath = os.path.join(subwatSubPath, subwatPerimSub[i])

Also, while arcpy.SearchCursor() should work, it's deprecated, and the new way to get a search cursor is arcpy.da.SearchCursor(in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause}) - see http://desktop.arcgis.com/en/desktop/latest/analyze/python/data-access-using-cursors.htm