ANSWER: I was missing the 'feature_dataset=' from line 14 of my test code. Credit goes to Xander Bakker for the sample code that pointed this out
arcpy.ListFeatureClasses(feature_dataset=test_dataset)
Hey All,
I have ArcMap installed at version 10.3.1 and I have several automation scripts, and I have recently noticed all my scripts that use arcpy.ListFeatureClasses() fatally error out at that tool.
Is someone else able to confirm they are able to run this without any critical errors?
I have just used the below code to test it bare basics, if someone else could please assist by changing the three variables to suit, does it run successfully?
import arcpy
connection = r"Database Connections\GISADMIN@SDE_Spatial@SDE-DB.sde"
arcpy.env.workspace = connection
test_dataset = r'Database Connections\GISADMIN@SDE_Spatial@SDE-DB.sde\SDE_SPATIAL.GISADMIN.Airport'
test_feature_within_dataset = r'Database Connections\GISADMIN@SDE_Spatial@SDE-DB.sde\SDE_SPATIAL.GISADMIN.Airport\SDE_SPATIAL.GISADMIN.Airport_Lighting_Zones'
print arcpy.Exists(test_dataset)
print arcpy.Exists(test_feature_within_dataset)
print 'It will fail at the next line of code'
print arcpy.ListFeatureClasses(test_dataset)
print '\n\nTEST COMPLETE'
I am considering updating my machine to the latest version, but before I take this step I am hoping someone can confirm it doesn't work at this version?
Thanks very much for your time.
Cheers
Solved! Go to Solution.
The arcpy.ListFeatureClasses should not crash. There might be something wrong with permissions, but if you are using a local .sde file and that works for you manually, then it should also work in the standalone pythons script. Below a simple sample of looping through all the featureclasses in de GDB,
import arcpy
import os
ws = r'' # your path to sde workspace
arcpy.env.workspace = ws
fdss = arcpy.ListDatasets()
fdss.append('') # for those fc that reside in the root of the sde ws
for fds in fdss:
fc_names = arcpy.ListFeatureClasses(feature_dataset=fds)
for fc_name in fc_names:
fc = os.path.join(ws, fds, fc_name)
# do somthing with the fc
print fc
List Feature Classes assumes the workspace, and therefore the path, has already been set. You are passing a full path to List Feature Classes when it is expecting just a name. Try:
print arcpy.ListFeatureClasses('SDE_SPATIAL.GISADMIN.Airport')
Good check... but crashing python is not what it should do. I suspect that there are other issues as well
I agree, there probably is something more. When I mimic the OP's situation, List Feature Classes simply returns an empty list, it doesn't crash Python. That said, it will be interesting if passing proper arguments will work or if it will still crash.
The arcpy.ListFeatureClasses should not crash. There might be something wrong with permissions, but if you are using a local .sde file and that works for you manually, then it should also work in the standalone pythons script. Below a simple sample of looping through all the featureclasses in de GDB,
import arcpy
import os
ws = r'' # your path to sde workspace
arcpy.env.workspace = ws
fdss = arcpy.ListDatasets()
fdss.append('') # for those fc that reside in the root of the sde ws
for fds in fdss:
fc_names = arcpy.ListFeatureClasses(feature_dataset=fds)
for fc_name in fc_names:
fc = os.path.join(ws, fds, fc_name)
# do somthing with the fc
print fc
Xander Bakker your sample code has pointed out my issue.
On line 11 you have this:
arcpy.ListFeatureClasses(feature_dataset=fds)
What i have been using in all my code is the equivalent of:
arcpy.ListFeatureClasses(fds)
So it seems for this tool to run on my machine I need to ensure I define the argument with feature_dataset=
Thanks for your assistance everybody, I have been pulling my hair out with this one. When I install 10.5 I would be curious to know if I need to continue to name the argument as above.
Sorry I didn't expand on what was happening, if I run in catalog python window it was returning an empty list, but if I ran a standalone python window it would crash as per my original post and screenshot.
thanks for your time
That single line of code crashes arcCatalog when I run it in the Python Window:
print arcpy.ListFeatureClasses('SDE_SPATIAL.GISADMIN.Airport')
This line works perfectly:
print arcpy.ListFeatureClasses(feature_dataset='SDE_SPATIAL.GISADMIN.Airport')
This script was working fine for over a year, I think the problem started when we updated from 10.3 to 10.3.1, but I cannot be 100% sure, it could be coincidental.
Thanks for your help.
Try a repair installation of desktop software