Saturday 17 March 2018

enterprise geodatabase - Arcpy ListFeatureClasses in same workspace differs when run from ArcMap VS IDLE



The following python script works when connecting to my dev ArcGIS server, from both the ArcMap python window and the IDLE python GUI/shell running on my dev workstation:


import arcpy
arcpy.env.workspace = "Database Connections/Connection to 172.20.0.XX.sde"
str(arcpy.ListFeatureClasses("*"))

Works: Prints list of all the feature classes in the Enterprise GeoDB






The following python script, which is the same as above but aside from the env.workspace value, DOES NOT work when connecting to my prod ArcGIS server from the IDLE python GUI/shell running on that same ArcGIS server, but DOES work from the ArcMap python window on that server...


When run from ArcMap 10.2.1 python window:


import arcpy
arcpy.env.workspace = "Database Connections/Connection to 172.20.0.XX.sde"
str(arcpy.ListFeatureClasses("*"))

Works: Prints list of all the feature classes in the Enterprise GeoDB




When run from IDLE python GUI/shell:



import arcpy
arcpy.env.workspace = "Database Connections/Connection to 172.20.0.XX.sde"
str(arcpy.ListFeatureClasses("*"))

Fails: Prints 'None'




The Windows user I'm logged into the prod ArcGIS server with is an admin, but The only thing I can come up with is



Note I have tried all of the following variations when setting the workspace:




  • arcpy.env.workspace = r"Database Connections\Connection to 172.20.0.49.sde"

  • arcpy.env.workspace = "Database Connections\Connection to 172.20.0.49.sde"

  • arcpy.env.workspace = "Database Connections" + os.sep + "Connection to 172.20.0.49.sde"

  • arcpy.env.workspace = os.path.join("Database Connections", "Connection to 172.20.0.49.sde")

  • Etc...



Answer



The answer which I found yesterday, and PolyGeo referenced in his comment above, was to use the full path to the sde instead of the relative path. I still don't understand why the IDLE GUI/shell can't use the relative path when the ArcMap python window can.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...