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.
|
|
Returns a list of fields found in the input value |
|
|
Returns a list of attribute indexes found in the input value |
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.management.CalculateField(fc, 'Flag', '1')
break
The properties of the field and index objects are listed below:
|
Property |
Explanation |
|---|---|
|
|
The name of the field. |
|
|
The alias name of the field. |
|
|
The name of the associated domain. |
|
|
|
|
|
|
|
|
|
|
|
The field's length. |
|
|
|
|
|
The field's scale. |
|
|
The field's precision. |
|
Property |
Explanation |
|---|---|
|
|
The name of the index. |
|
|
|
|
|
|
|
|
A list of |
Tip:
ListFields and ListIndexes can be used to limit the results based on name and type.