I am not getting any response from this script and no error displayed at all
I am writing this script to help me display the feature classes in my geodatabase
Here is my script
import arcpy
arcpy.env.workspace = r"Q:\basemaps\ALTA\FileGeodatabase\AB_IHS_GIS_DATA.gdb"
logfile = open(r"C:\tmp\log.txt ","w")
fcLst = arcpy.ListFeatureClasses()
for fc in fcLst:
logfile.write(fc + "\n")
logfile.close()
1 Answer 1
Make sure the directory C:\tmp exists. If it does not, your third call will fail. I normally use unicode and double slashes for my workspaces.
u"J:\\restored-20101025\\basemaps\\ALTA\\FileGeodatabase\\GEOBASE_GIS_DATA.gdb"
But the big problem is that your logfile.close() is inside your for loop. That needs to be outside the for loop, or else you will close the logfile after the first featureclass name is written. You also have a typo in your variable assignment for fcLst.
import arcpy, os
arcpy.env.workspace = u"J:\\restored-20101025\\basemaps\\ALTA\\FileGeodatabase\\GEOBASE_GIS_DATA.gdb"
if os.path.exists(arcpy.env.workspace):
if not os.path.isdir(r"C:\tmp"):
os.mkdir(r"C:\tmp")
logfile = open(r"C:\tmp\log.txt", "w")
fcList = arcpy.ListFeatureClasses()
dsList = arcpy.ListDatasets()
for fc in fcList:
logfile.write(fc+"\n")
for ds in dsList:
fcList = arcpy.ListFeatureClasses("","All",ds)
for fc in fcList:
logfile.write(fc+"\n")
logfile.close()
else:
print("Workspace does not exist.")
-
yes the temp folder does exist and i tried re-writing the code again and now i dont get any error at but it does not display the feature classesShade– Shade2012年08月03日 16:18:49 +00:00Commented Aug 3, 2012 at 16:18
-
Just added a code sampleblord-castillo– blord-castillo2012年08月03日 16:22:29 +00:00Commented Aug 3, 2012 at 16:22
-
I got the problem sorted out. The feature classed were in another subfolder inside the geodatabase. my code is right so what happens is that when i run the script it list the feature classes inside the tmp folder in my c drive as specifiedShade– Shade2012年08月03日 16:28:15 +00:00Commented Aug 3, 2012 at 16:28
-
Sounds like they were in a feature dataset. I modified the script again to deal with those too. The one feature class this script will not get to is a feature class inside a feature type inside a feature dataset, e.g. the feature classes inside a parcel fabric inside a feature dataset.blord-castillo– blord-castillo2012年08月03日 17:17:14 +00:00Commented Aug 3, 2012 at 17:17
-
2Hi @Shade, if you found blord-castillo's answer helpful, would you mind "accepting" it? There's a checkbox beneath the voting buttons. It's a small thing, but it's part the currency that drives stack exchange. You might find that people are less willing to help you if you don't participate.canisrufus– canisrufus2012年08月03日 22:12:32 +00:00Commented Aug 3, 2012 at 22:12
Explore related questions
See similar questions with these tags.