The attached picture shows my result on ArcGIS Pro. It shows all the elements in a geodatabase that a user chooses.

enter image description here

It only displays catalogpath to the elements, but now I need to describe, for each of these element such as Q:\ClassData\317\2020\HwyCorridor.gdb\rawdata, other descriptions. For now, I just want to figure out how to extract the information of shapetype, and display it right under the catalogpath.

The two codes with my comment are the ones I am struggling with. If I take out these two, the code runs without any error and gives me the result as shown in the attached picture.

def data_report(workspace):

elements = defaultdict(list)

walk = arcpy.da.Walk(workspace, topdown=True)

for dirpath, dirnames, filenames in walk:
    for dirname in dirnames:  # 'FeatureDataset'
        desc = arcpy.da.Describe(os.path.join(dirpath, dirname))

    for filename in filenames:
        desc = arcpy.da.Describe(os.path.join(dirpath, filename))

report = []

for element_type, element_list in elements.items():
    report += [f"{element_type}:"]
    for element_description in element_list:
        report +=  [f"\t\t{element_description['catalogPath']}"] 
        #Describe the element
        desc2 = arcpy.da.Describe(element_description['catalogPath'])

#If Datatype is featureclass, add its shapetype to the report
if dataType == featureClass:
    report+= [f"\t\t\{"Shape Type :   " + desc.shapeType}")]

return report
  • The way I inspect dictionaries, lists, sets, etc is to print them. The code that you’ve presented includes no print statements. – PolyGeo Feb 14 at 23:26
  • 1
    Please in future when you get an error with your python code, include the entire exception text (not just the final error message) as text, formatted as code using the {} button. – user2856 Feb 15 at 7:05

arcpy.da.Describe returns a dictionary not a Describe object like the old arcpy.Describe function. As such, it doesn't have a .shapeType property, it has a shapeType key, i.e element_description['shapeType']. I suggest you inspect the dictionary and also have a look at the arcpy.da.Describe documentation to see what keys you can use.

You're also misusing the f"format string". You don't concatenate, you just use the variable inside {} in the string, i.e.

report+= [f"\t\t\"Shape Type :  {element_description['shapeType']}")]

Note that da.Describe is ArcGIS Pro only and f"{format}" strings are Python 3 only

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.