When creating python scripts, I find that there items missing from the intellisense popups in the Python window. I also see that the same items are missing when examining an object with dir().
For example:-
cursor = arcpy.SearchCursor("My Feature Class")
row = cursor.next()
dir(row)
['__class__', '__cmp__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__passthrough_to_ao__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_arc_object', '_go', 'getValue', 'isNull', 'setNull', 'setValue']
dir(row.SHAPE)
['JSON', 'WKB', 'WKT', '__add__', '__class__', '__cmp__', '__delattr__', '__dict__', '__doc__', '__format__', '__from_scripting_arc_object__', '__geo_interface__', '__getattribute__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__type_mapping__', '__type_string__', '__weakref__', '__xor__', '_arc_object', '_fromGeoJson', '_go', '_passthrough', 'area', 'boundary', 'buffer', 'centroid', 'clip', 'contains', 'convexHull', 'crosses', 'cut', 'difference', 'disjoint', 'distanceTo', 'equals', 'extent', 'firstPoint', 'getArea', 'getLength', 'getPart', 'hullRectangle', 'intersect', 'isMultipart', 'labelPoint', 'lastPoint', 'length', 'length3D', 'measureOnLine', 'overlaps', 'partCount', 'pointCount', 'positionAlongLine', 'projectAs', 'queryPointAndDistance', 'snapToLine', 'spatialReference', 'symmetricDifference', 'touches', 'trueCentroid', 'type', 'union', 'within']
Note that SHAPE is missing from the output of dir(row). In the intellisense popup it shows getValue, isNull, setNull, setValue, but not SHAPE.
This makes it a bit more difficult when writing scripts as I have to remember that the object is missing.
Solved! Go to Solution.
Remember that SHAPE
is a special case, it's a column name in the row. All of the Row's column name attributes are computed at the very last possible minute. The class has its usual attributes like its getValue method, but then it overrides the __getattr__
method as a last-ditch chance for the class instance to return a value for object.SOMETHING
before Python throws an AttributeError
.
TL;DR: The row class doesn't have each individual column name as an attribute. It instead uses some Python magic to allow Row.COLUMN
to act as syntactic sugar for Row.getValue("COLUMN")
.
Remember that SHAPE
is a special case, it's a column name in the row. All of the Row's column name attributes are computed at the very last possible minute. The class has its usual attributes like its getValue method, but then it overrides the __getattr__
method as a last-ditch chance for the class instance to return a value for object.SOMETHING
before Python throws an AttributeError
.
TL;DR: The row class doesn't have each individual column name as an attribute. It instead uses some Python magic to allow Row.COLUMN
to act as syntactic sugar for Row.getValue("COLUMN")
.
Thanks for the helpful answer!