I am trying to create a new script with a hard-coded geodatabase filename, that lists the feature classes it contains to the console. I know there are several ways to do this, but I decided to to use ListFeatureClasses function. I barely started studying Python, so I know very basic stuff, but I would like to get help with this.
I tried the following code, but it does not print anything and does not even give me any error message. I opened up ArcGIS Pro, added the geodatabase to my map, and wrote this code in the built-in Python console. Is there any step I am missing or something wrong with my code?
import arcpy
import os
arcpy.env.workspace = "X:\311\Obtaining GIS Data\TaxParcels.gdb"
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)
print(fc)
r"your\path"
, escape your backslashes"your\\path"
or use a forward slash"your/path
instead. eg.print(r"X:\311\Obtaining...")
X:\311\Obtaining...
print("X:\311\Obtaining...")
X:É\Obtaining...
– user2856 Jan 29 '20 at 0:04datasets = ['']...
line for? What is the point of thepath = ...
line? path is never used anywhere. Don't use strings with "\" in them, unless you either escape the "\" characters with "\\" or you use a raw string (prefixed withr"..."
) or use normal (forward) slashes instead of backslashes. Ie,/
. Python (including arcpy) is smart enough to treat forward slashes as a file path separator character even on Windows (the only commonly used OS that doesn't use/
by default). – Son of a Beach Jan 29 '20 at 0:47