Though the documentation refers to a "Describe object", it must be some sort of C class (apparently via the arcgisscripting.create function), instead of a Python class. The standard Python introspection methods don't turn up much information (see below).
If one wishes to summarize all the known info of a dataset, how might one dynamically identify which properties apply to the current instance--without writing a long series of if statements and/or going through all the potential properties?
For reference: given a variable named "desc" returned from a call to arcpy.Describe, here are the results of some inspection and introspection operations:
>>> type(desc)
<type 'geoprocessing describe data object'>
>>> dir(desc)
[]
>>> desc.__name__
'Describe Object'
>>> desc.__class__
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: DescribeData: Method __class__ does not exist
>>> desc.__repr__
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: DescribeData: Method __repr__ does not exist
>>> isinstance(desc, object)
True
>>> desc.__dict__
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
AttributeError: DescribeData: Method __dict__ does not exist
>>> help(desc)
Help on geoprocessing describe data object object:
Describe Object = class geoprocessing describe data object(object)
>>> print(inspect.getmodule(desc))
None
>>> inspect.getclasstree(desc)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\ArcGISx6410.4\Lib\inspect.py", line 726, in getclasstree
for c in classes:
TypeError: 'geoprocessing describe data object' object is not iterable
>>> inspect.getmro(desc)
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python27\ArcGISx6410.4\Lib\inspect.py", line 346, in getmro
_searchbases(cls, result)
File "C:\Python27\ArcGISx6410.4\Lib\inspect.py", line 337, in _searchbases
for base in cls.__bases__:
AttributeError: DescribeData: Method __bases__ does not exist
Solved! Go to Solution.
addendum
examples:
desc['areaFieldName'] # 'Shape_Area'
desc['baseName'] # featureclass name
desc['catalogPath'] # full path to the featureclass
desc['datasetType'] # FeatureClass
desc['dataType'] # 'FeatureClass'
desc['extent'] # extent object
desc['file'] # filename without path
desc['featureType'] # 'Simple'
desc['hasOID'] # True
desc['hasM'] # False
desc['hasZ'] # False
desc['lengthFieldName'] # 'Shape_Length'
desc['name'] # layer name, no path
desc['OIDFieldName'] # 'OBJECTID'
desc['path'] # full catalog path minus name
desc['shapeFieldName'] # 'Shape'
desc['shapeType'] # Polygon
desc['spatialReference'] # spatial reference object
result = [(k, desc[k]) for k in desc.keys()] # to get them all
If you are particularly interested in seeing what is going on behind the scenes, examine the __init__ trail and see what is being imported and how and where it takes you and what properties etc are revealed. The lack of many 'pythonic' properties, I suspect, is intentional
import inspect
inspect.getabsfile(arcpy) or inspect.getfile(arcpy)
'c:\\arcpro\\resources\\arcpy\\arcpy\\__init__.py'
# examine __init__ and its children