Skip To Content

Using fields and indexes

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.

ListFields(dataset, wild_card, field_type)

Returns a list of fields found in the input value

ListIndexes(dataset, wild_card)

Returns a list of attribute indexes found in the input value

List functions

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:

PropertyExplanation

name

The name of the field.

aliasName

The alias name of the field.

domain

The name of the associated domain.

editable

True, if the field is editable.

isNullable

True, if the field is nullable.

required

True, if the field is required.

length

The field's length.

type

SmallInteger, Integer, Single, Double, String, Date, OID, Geometry, BLOB.

scale

The field's scale.

precision

The field's precision.

Field properties

PropertyExplanation

name

The name of the index.

isAscending

True, if the index sorts in ascending order.

isUnique

True, if the index is unique.

fields

A list of Field objects. This is the same as using Describe's field property.

Index properties

Tip:

ListFields and ListIndexes can be used to limit the results based on name and type.