Field

描述

字段对象表示表中的列。字段有许多属性,最常用的是其名称和类型。

讨论

可通过 ListFields 和 Describe 功能访问字段属性。

更新字段属性时仅会更新字段对象,而不会更改表或要素类中的实际字段。

语法

 Field  ()

属性

属性说明数据类型
aliasName
(可读写)

字段的别名。

String
baseName
(可读写)

非限定字段名称。

String
defaultValue
(可读写)

字段的默认值。

Variant
domain
(可读写)

关联属性域的名称。

String
editable
(可读写)

可编辑状态:True 字段可编辑时。

Boolean
isNullable
(可读写)

指示该字段是否可包含空值。

Boolean
length
(可读写)

字段的长度。

Integer
name
(可读写)

字段的名称。

String
precision
(可读写)

字段值的精度。

Integer
required
(可读写)

指示字段是否为必填字段。无法删除必填字段。

Boolean
scale
(可读写)

字段的小数位数。

Integer
type
(可读写)

字段类型。

  • Blob —Blob
  • Date —日期型
  • Double —双精度型
  • Geometry —几何
  • GlobalID —全局 ID
  • Guid —Guid
  • Integer —整型(长整型)
  • OID —对象 ID
  • Raster —栅格
  • Single —单精度(浮点型)
  • SmallInteger —小整型(短整型)
  • String —字符串(文本)
注:

字段对象的 type 属性与针对添加字段工具 field_type 参数列出的选项不完全匹配。要允许添加字段工具使用所有类型关键字,需映射以下字段类型:Integer 至 LONG、String 至 TEXT 以及 SmallInteger 至 SHORT。

String

代码示例

字段示例

显示指定要素类的字段属性。

import arcpy

feature_class = "c:/data/counties.shp"

# Create a list of fields using the ListFields function
fields = arcpy.ListFields(feature_class)

# Iterate through the list of fields
for field in fields:
    # Print field properties
    print("Field:       {0}".format(field.name))
    print("Alias:       {0}".format(field.aliasName))
    print("Type:        {0}".format(field.type))
    print("Is Editable: {0}".format(field.editable))
    print("Required:    {0}".format(field.required))
    print("Scale:       {0}".format(field.scale))
    print("Precision:   {0}".format(field.precision))

相关主题