When described, feature classes and tables have a fields property that returns a list of field objects, and an indexes property that returns a list of index objects. Each field or index object has a number of properties that can be used to explore the object. Alternatively, the ListFields and ListIndexes functions can be used to create the same lists. The following example shows how to create a field list and loop through the contents to find a specific field.
import arcpy fc = 'D:/St_Johns/data.gdb/roads' # Get a list of field objects # fields = arcpy.ListFields(fc, 'Flag') for field in fields: # Check the field name, perform a calculation when finding the field 'Flag' # if field.name == 'Flag': # Set the value for the field and exit loop # arcpy.CalculateField_management(fc, 'Flag', '1') break
The properties of the field and index objects are listed below:
The name of the field.
The alias name of the field.
The name of the associated domain.
True, if the field is editable.
True, if the field is nullable.
True, if the field is required.
The field's length.
SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, BLOB.
The field's scale.
The field's precision.
The name of the index.
True, if the index sorts in ascending order.
True, if the index is unique.
A list of Field objects. This is the same as using Describe's field property.