使用字段和索引
在描述要素类和表时,要素类和表具有一个用于返回 Field 对象列表的 fields 属性,以及一个用于返回 Index 对象列表的 indexes 属性。 每个字段或索引对象都有许多可用于浏览对象的属性。 另外,使用 ListFields 和 ListIndexes 函数也可以创建相同的列表。
|
|
返回在输入值中找到的字段的列表 |
|
|
返回在输入值中找到的属性索引的列表 |
下面的示例描述了如何创建字段列表以及循环浏览列表内容以查找特定的字段。
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
以下列出了字段和索引对象的属性:
|
属性 |
说明 |
|---|---|
|
|
字段的名称。 |
|
|
字段的别名。 |
|
|
关联域名称。 |
|
|
字段可编辑时为 |
|
|
字段可为空时为 |
|
|
字段为必填字段时为 |
|
|
字段长度。 |
|
|
|
|
|
字段小数位数。 |
|
|
字段的精度。 |
|
属性 |
说明 |
|---|---|
|
|
索引的名称。 |
|
|
索引按升序排序时为 |
|
|
索引唯一时为 |
|
|
|
提示:
ListFields 和 ListIndexes 可用来基于名称和类型限制结果。