Zusammenfassung
Lists all of the datasets in a workspace. Search conditions can be specified for the dataset name and dataset type to limit the list that is returned.
Auswertung
The workspace environment must be set first before using several of the List functions, including ListDatasets, ListFeatureClasses, ListFiles, ListRasters, ListTables, and ListWorkspaces.
Syntax
ListDatasets ({wild_card}, {feature_type})
Parameter | Erklärung | Datentyp |
wild_card | The wild_card limits the results returned. If no wild_card is specified, all values are returned. | String |
feature_type | The feature type to limit the results returned by the wildcard argument. Valid dataset types are:
(Der Standardwert ist All) | String |
Rückgabewert
Datentyp | Erklärung |
String | A list containing dataset names returned from the function, limited by the wildcard and feature type arguments. |
Codebeispiel
ListDatasets example
List Feature Dataset names that start with C.
import arcpy
arcpy.env.workspace = "c:/data"
# Print to the Interactive window all the feature datasets in the
# workspace that start with the letter C.
datasets = arcpy.ListDatasets("C*", "Feature")
for dataset in datasets:
print(dataset)
ListDatasets example 2
List Feature Dataset names that start with c or f, start with letters except c, or contain both c and f.
import arcpy
arcpy.env.workspace = 'c:/data'
# Print to the Interactive window all the feature datasets in the
# workspaces that start with the letter c or f.
datasets1 = list(set(arcpy.ListDatasets("c*", "Feature")) |
set(arcpy.ListDatasets("f*", "Feature")))
print(datasets1)
# workspaces that start with the letters except c
datasets2 = list(set(arcpy.ListDatasets("*", "Feature")) -
set(arcpy.ListDatasets("c*", "Feature")))
print(datasets2)
# workspaces that contain both the letter c and f
datasets3 = list(set(arcpy.ListDatasets("*c*", "Feature")) &
set(arcpy.ListDatasets("*f*", "Feature")))
print(datasets3)