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....
B.
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:
print(dataset)
Geo... what about toolbox and tool ? whats'up with that?
Ha, yeah, forgot about those. The many lives of datasets; unfortunately, the meaning is context specific, and sometimes the context only seems to be in the developers' heads.
I guess my original question wasn't so stupid afterall. It's been a long while since I dabbled in this kind of stuff - interesting to see some things haven't changed much when it comes to defining classes/objects in libraries like ArcPy/Python....I thought it would have been much cleaner by now
Thanks again Dan. I don't know how often I'll be here - I'm not really working with ArcPy/Python as much as I'd like, rather, only use it for scripting/batch processing when I have something large to run (usu. raster analyses/models). Great to have this forum - and great to see you staying on top of it all for us!
If you are working on listing geographic data, I suggest using the ArcPy Data Access Walk function. The ArcPy Walk function mimics the form and function of Python's os.walk function, the standard way of listing file system contents. ArcPy Walk can even be coupled with ArcPy Describe to print the geodatabase contents and data type:
import os
gdb = #path to geodatabase walk = arcpy.da.Walk(gdb) for dirpath, dirnames, filenames in walk: if dirpath != gdb: desc = arcpy.Describe(dirpath) print "{:<30s}{}".format(os.path.relpath(dirpath, gdb), desc.datatype) for file in filenames: filepath = os.path.join(dirpath, file) desc = arcpy.Describe(filepath) print "{:<30s}{}".format(os.path.relpath(filepath, gdb), desc.datatype)
Thanks Joshua - this is extremely helpful!