arcpy.Describe/*string*.format compared in code, with >=1/==True comparison [on hold]
The Problem:I am having issues with the code below. I have narrowed it down to the "'for fc in fc_list'/'for fld in fld_list'" loop, and believe it is an issue with the Describe function. I have read the Esri help document on Describe but am not seeing what is wrong.
I am trying to get a nicely formatted output(print), that describes the FeatureClass, and lists the names and types of fields of all FeatureClasses in a geodatabase.
What are my issues here? Is it in the Describe function as I suspect? It will run OK (in PyScripter and IDLE), but not actually print what is needed, nor report any errors.
When tested against an actual geodatabase, fc_count prints the correct number of FeatureClasses.
"#": some code is commented out to show progression through edits.
Update2 The ==True with the string.format(field) operation gave partial results. the >=1 with the arcpy.Describe function gave partial results. The answer was a combination of the two, >=1 and string.format. But, Why? There is another thread with this discussion. However, I'm unsure, if they're the same, why it matters?
Update: It still doesnt operate when ==True isreplaced with the >=1 suggested before. The same ==True setup using the raster and table equivalents (i.e. ListRaster) print just fine; however those loops dont utilize a Describe function because I am not trying to get the field names/types from them. There is something wrong when translated into this loop. If its not the Describe function like I suspect, then what is it? If its the if statement, as suggested, then where is the issue?
Describe:
import arcpy, os, sys from arcpy import env arcpy.env.overwriteOutput = True #gdb = raw_input(r"Please insert the full pathname of the Input Geodatabase :") gdb = r"F:\........\&&&&&.gdb" print ("Geodatabase: " +gdb) env.workspace = gdb env.scratchworkspace = gdb fc_list = arcpy.ListFeatureClasses() fc_count = len(fc_list) #if fc_count == True: if fc_count >= 1: print ("\nFeatureClasses:") for fc in fc_list: print ("\t" + fc) fclass = gdb + "\\" + fc fld_list = arcpy.ListFields(fclass) for fld in fld_list: print(" \t \t {0} ({1})".format(fld.name, fld.type)) #name = arcpy.Describe(fld).name #kind = arcpy.Describe(fld).type #name = "x" #kind = "y" #print ("\t\t" + name + ("(" + kind + ")"))
أكثر...
The Problem:I am having issues with the code below. I have narrowed it down to the "'for fc in fc_list'/'for fld in fld_list'" loop, and believe it is an issue with the Describe function. I have read the Esri help document on Describe but am not seeing what is wrong.
I am trying to get a nicely formatted output(print), that describes the FeatureClass, and lists the names and types of fields of all FeatureClasses in a geodatabase.
What are my issues here? Is it in the Describe function as I suspect? It will run OK (in PyScripter and IDLE), but not actually print what is needed, nor report any errors.
When tested against an actual geodatabase, fc_count prints the correct number of FeatureClasses.
"#": some code is commented out to show progression through edits.
Update2 The ==True with the string.format(field) operation gave partial results. the >=1 with the arcpy.Describe function gave partial results. The answer was a combination of the two, >=1 and string.format. But, Why? There is another thread with this discussion. However, I'm unsure, if they're the same, why it matters?
Update: It still doesnt operate when ==True isreplaced with the >=1 suggested before. The same ==True setup using the raster and table equivalents (i.e. ListRaster) print just fine; however those loops dont utilize a Describe function because I am not trying to get the field names/types from them. There is something wrong when translated into this loop. If its not the Describe function like I suspect, then what is it? If its the if statement, as suggested, then where is the issue?
Describe:
import arcpy, os, sys from arcpy import env arcpy.env.overwriteOutput = True #gdb = raw_input(r"Please insert the full pathname of the Input Geodatabase :") gdb = r"F:\........\&&&&&.gdb" print ("Geodatabase: " +gdb) env.workspace = gdb env.scratchworkspace = gdb fc_list = arcpy.ListFeatureClasses() fc_count = len(fc_list) #if fc_count == True: if fc_count >= 1: print ("\nFeatureClasses:") for fc in fc_list: print ("\t" + fc) fclass = gdb + "\\" + fc fld_list = arcpy.ListFields(fclass) for fld in fld_list: print(" \t \t {0} ({1})".format(fld.name, fld.type)) #name = arcpy.Describe(fld).name #kind = arcpy.Describe(fld).type #name = "x" #kind = "y" #print ("\t\t" + name + ("(" + kind + ")"))
أكثر...