I'm an ArcPy neophyte/beginner - and this might be a stupid question, but I simply want to return a list of all the contents in a .gdb. When I run the arcpy,listdatasets("*","Feature") function, it appears to work (no errors reported), but I do not 'see' anything. I used it with the 'print' function as well (using the example code provided in the help - copied below) - but I still don't see anything. Where does it go? I only need to see it print to screen so I can copy/paste it....
import arcpy arcpy.env.workspace = "c:/data"
# Print to the Interactive window all the feature datasets in the
# workspace that start with the letter
datasets = arcpy.ListDatasets("C*", "Feature")
for dataset in datasets:
I think what you want is ListFeatureClasses ArcGIS Help (10.2, 10.2.1, and 10.2.2)
"List all feature classes in a geodatabase, including any within feature datasets" which is shown on that page, but I used the "raw" path name instead
arcpy.env.workspace = r"c:\_temp"
datasets = arcpy.ListDatasets(feature_type='feature')
datasets = [''] + datasets if datasets is not None else 
for ds in datasets:
for fc in arcpy.ListFeatureClasses(feature_dataset=ds):
path = os.path.join(arcpy.env.workspace, ds, fc)
Since you are new to python and I'm assuming the forums, I'll suggest a couple other links to get you started on the right foot.
Anyway, I hope this help, but if not, reply with what issues you are having, version you are using, etc.
You may be listing the wrong type of object ... see the list available
Also, install an IDE like pythonwin or pyscripter, the builtin IDE isn't great
In interactive mode with one shapefile in pythonwin
>>> import arcpy
>>> arcpy.env.workspace = "f:/temp"
>>> ds = arcpy.ListFeatureClasses()
>>> for d in ds:
In arcmap's IDE
>>> import arcpy
>>> arcpy.env.workspace = "F:/temp"
>>> d = arcpy.ListFeatureClasses()
>>> for i in d:
If nothing prints out nothing was found, so you should really check for it before you run through any loops
Brian... a good place to bookmark is just the documentation, then you can navigate to Arcpy to find the syntax for methods, properties and the like.
There is one for ArcMap and for Pro which are more or less the same. Also Geoprocessing has a link to Tool Reference should you want to incorporate the functionality of an ArcToolbox tool directly within a script.
Every link (almost) has scripting syntax and then you can go to my Py Links blog post where I keep a running list of changes to arcmap and pro as they would affect script functionality.
FWIW, I've often found arcpy's definition of "dataset" a little confusing. For example, the arcpy.Describe() "Dataset type" property will return any of these:
However, when I use arcpy.ListDatasets() on a workspace with a bunch of tables and a single feature dataset, only the feature dataset is returned. I do agree with Joshua Bixby that arcpy.da.Walk() is the most consistent way to list everything (with the added benefit of being able to "drill down" into feature datasets).
So to summarize, my concept (and please correct me if I am mistaken!) is that a "dataset" in ArcGIS is any of the things listed in the graphic above.
In my opinion, the documentation screenshot you posted is a documentation bug, or the reflection of a software bug in documentation. The behavior you see with arcpy.ListDatasets() is expected, and I would argue correct. Datasets are container "data sets," e.g., feature dataset, raster dataset, mosaic dataset, parcel fabric, and others. A feature class isn't a dataset, but in a general sense it is a "data set." There is an Abbott and Costello skit in there somewhere.
Where the bug, as I see it, comes into play is with the ArcPy Describe object. When describing a feature class, the datasetType property and dataType property both return the same value. That same is true when describing feature datasets. Interestingly enough, the same is also true for topologies and every other dataset I have tried. Which raises the question, why have two properties instead of just one? One would think a non-dataset wouldn't support the datasetType property, but it does, and that causes confusion as to what exactly a dataset is.
I won't even get started on "Geo." I have been pushing for them to either clearly define it or remove it because its current implementation makes no sense at all.