Can't get searchcursor, listfields etc to work - get same error message each time

2089
7
01-02-2012 06:05 AM
by Anonymous User
Not applicable
Original User: bhickman1989@gmail.com
Original Date: 2012-01-02T08:05:42-0600

Hi there,

I've been struggling with this for a while now, for some reason I'm unable to get listfields and searchcursor to work in Python. Below is a very simple script I'm using to test my system and I get the error message seen below:

import arcpy, os, sys, arcgisscripting

mxd = arcpy.mapping.MapDocument(r"C:\Users\Ben\Documents\E.ON Work\Practise.mxd")
arcpy.env.workspace = "C:\Users\Ben\Documents\E.ON Work\Practise.mxd"
fc = "C:\Users\Ben\Documents\ArcGIS\OS OpenData\scotland_and_wales_region_region.shp"


rows = arcpy.SearchCursor("scotland_and_wales_region_region")
#Have also tried rows = arcpy.SearchCursor(fc) and get the same error message

del mxd


Traceback (most recent call last):
File "C:\Python26\ArcGIS10.0\Lib\site-packages\Pythonwin\pywin\framework\scriptutils.py", line 325, in RunScript
exec codeObject in __main__.__dict__
File "C:\Users\Ben\Documents\E.ON Work\Scripts\Row work.py", line 10, in <module>
rows = arcpy.SearchCursor("scotland_and_wales_region_region")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\__init__.py", line 804, in SearchCursor
return gp.searchCursor(*args)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\geoprocessing\_base.py", line 357, in searchCursor
self._gp.SearchCursor(*gp_fixargs(args)))
RuntimeError: ERROR 999999: Error executing function.

I'm pretty new to programming and python in general but everywhere I look I can't see anyone getting the same error. Is there something else I need to import? The two python codes that the error is referring to are attached.

Would really appreciate some help on this one.

Thanks in advance!

Ben
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus
In Python either use:
raw notation    r"c:\temp"
double backslashes "c:\\temp"
single foreslashes "c:/temp"
when specifying path names
0 Kudos
by Anonymous User
Not applicable
Original User: bhickman1989@gmail.com

Dan
Thanks for that, but even when I do take up your suggestion the exact same error message is coming up - namely from the searchcursor function

Any ideas?

Cheers

Ben
0 Kudos
MathewCoyle
Frequent Contributor
Try importing less. Something like this should not have a problem as long as the shapefile actually exists in that location and isn't already open by another application.

import arcpy

fc = r"C:\Users\Ben\Documents\ArcGIS\OS OpenData\scotland_and_wales_region_region.shp"

rows = arcpy.SearchCursor(fc)
0 Kudos
by Anonymous User
Not applicable
Original User: bruce.nielsen

Your workspace should be a folder or geodatabase, not an .mxd
0 Kudos
BenHickman
New Contributor
Thanks for the replies. I tried that code and got exactly the same error message (?) With the _base script there is the following lines:

class Geoprocessor(object):

#a few defined functions

def searchCursor(self, *args):
"""GP function SearchCursor"""
from ..arcobjects.arcobjectconversion import convertArcObjectToPythonObject
return convertArcObjectToPythonObject(
self._gp.SearchCursor(*gp_fixargs(args)))

Does that look right? Also the _init_ script looks very short (see my earlier attached files)

I really appreciate any help you can give on this!
With regards to calling the mxd this is what I've been doing for vrious scripts before and they've all worked perfectly...

Cheers

Ben
0 Kudos
by Anonymous User
Not applicable
Original User: jjbuckle

Was this ever resolved?  I'm getting the exact same error message with a script that worked fine 3 weeks ago. I can't execute even the simplest SearchCursor.
0 Kudos
LauraGriffin
New Contributor
Double check your file pathnames - it probably just can't find the file.  For example it doesn't like that extra space in the OP's code.  I was going crazy with this error message until I realized I was trying to use the extension for a File geodatabase (.gdb) with my personal geodatabase (.mdb).
0 Kudos