I have a very simple script that isn't working.
import arcpy
workspace = "C:\\Users\\Work\\AppData\\Roaming\\ESRI\\Desktop10.3\\ArcCatalog\\master.sde"
arcpy.env.workspace = workspace
wire = "gis.DBO.wire"
with arcpy.da.SearchCursor(wire, "id") as cursor:
for row in cursor:
print row[0]
It returns RuntimeError: cannot open 'gis.DBO.wire'
UPDATED
I still haven't figured this out. I just did a repair on ArcGIS Desktop 10.3, and that didn't solve it. So, then I removed Python, and reinstalled it and it still doesn't work.
I have this script I've tried running in PyScripter and IDLE:
import arcpy
sde = "C:\\Temp\\Data.sde"
domains = arcpy.da.ListDomains(sde)
I get:
And, yes it is a valid sde connection.
If I do the exact same code above in the Python window of ArcCatalog it works fine.
Here's the IDLE error:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
domains = arcpy.da.ListDomains(sde)
RuntimeError
2 Answers 2
I think the problem here is that you are treating the SearchCursor() like a geo-processing tool. Geo-processing tools can honour 1 or more environment settings (which you find out by looking at the help for the tool) and one such setting is workspace.
Nowhere on the help page for SearchCursor() does it state that Workspace is an environment setting that it honours. In fact I don't think it honours any! So you need to provide the full path because currently you are providing a string "gis.DBO.wire"
.
-
1
SearchCursor
definitely does honor the set workspace because I use it fine on a different computer.geogeogeo– geogeogeo2016年01月14日 03:02:33 +00:00Commented Jan 14, 2016 at 3:02
You can do that. I think it works. I haven't sde connection. I can't test
import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace ="Database Connections/master.sde"
# check name
fc_list = arcpy.ListFeatureClasses()
for fcname in fc_list:
print fc
#if wire is named gis.DBO.wire
# use in cursor full name
fcname = "gis.DBO.wire"
fc = os.path.join(env.workspace,fcname)
# check if exist
if arcpy.Exists(fc):
print "Featureclass Exist"
with arcpy.da.SearchCursor(fc, "id") as cursor:
for row in cursor:
print row[0]
Explore related questions
See similar questions with these tags.
workspace = r"Database Connections\master.sde"
?