I am trying to describe, list, and test for existence of featureclasses in a geodatabase using the following code.
import arcpy
#Set geoprocessing environments
arcpy.env.workspace = "C:""
#Check if the environment workspace exists
if arcpy.Exists(arcpy.env.workspace):
print "Workspace exists" + " " + "..." + " " + "getting coordinate systems" + " " + "..."
#If workspace does not exist, statement will print "does not exist"
else:
print "Workspace does not exist"
fcList = arcpy.ListFeatureClasses("*", "POLYGON")
for fc in fcList:
desc = arcpy.Describe(fc)
print fc + "" + ":" + "" + str(desc.SpatialReference.name)
While the current code does work when the workspace does exist, when I try to give it a non-existing workspace I get an error message:
The issue appears to be around the line code that allows me to print the list of feature classes in the geodatabase along with there spatial reference information for fc in fcList: TypeError: "NoneType" object is not iterable
I simply want it to print statement following else: to print "the workspace does not exist", but I do not know how to actually accomplish that.
r"C:\mydata"
. String math is actually quite slow, so usingstring.format()
is the best way to format messages.