Skip to main content

Field

汇总

Field 对象表示表格中的一列。

讨论

Field 属性可通过 ListFieldsDescribe 函数访问。

更新字段属性只会更新 Field 对象;不会对表或要素类中的实际字段进行任何更改。

语法

Field()

属性

名称 说明 数据类型

aliasName

(读取和写入)

字段的别名。

String

baseName

(读取和写入)

非限定字段名称。

String

defaultValue

(读取和写入)

字段的默认值。

Variant

domain

(读取和写入)

关联域名称。

String

editable

(读取和写入)

指定字段是否可以编辑。

Boolean

isNullable

(读取和写入)

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

Boolean

length

(读取和写入)

字段长度。

Integer

name

(读取和写入)

字段的名称。

String

precision

(读取和写入)

字段值的精度。

对于日期类型的字段,精度可以是 0 或 1。

  • 0 - 常规日期字段。 存储的数据精确到秒(一分钟的 1/60)。

  • 1 - 高精度日期字段。 存储的数据精确到毫秒(一秒的 1/1000)。

Integer

required

(读取和写入)

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

Boolean

scale

(读取和写入)

字段比例。

Integer

type

(读取和写入)

指定字段类型。

  • Blob—此字段类型将为 BLOB。

  • BigInteger—此字段类型将为大整型。

  • Date—此字段类型将为日期。

  • DateOnly—此字段类型将为仅日期。

  • Double—此字段类型将为双精度型。

  • Geometry—此字段类型将为几何。

  • GlobalID—此字段类型将为全局 ID。

  • Guid—此字段类型将为 GUID。

  • Integer—此字段类型将为整型(长整型)。

  • OID—此字段类型将为对象 ID。

  • Raster—此字段类型将为栅格。

  • Single—此字段类型将为单精度(浮点型)。

  • SmallInteger—此字段类型将为小整型(短整型)。

  • String—此字段类型将为字符串(文本)。

  • TimeOnly—此字段类型将为仅时间。

  • TimestampOffset—此字段类型将为时间戳偏移。

注:

Field 对象的 type 属性值与 添加字段 工具的 field_type 参数所使用的关键字不完全匹配。 尽管如此,所有 Field 对象的 type 值均可用作此参数的输入。 不同的字段类型映射如下:

  • IntegerLONG

  • StringTEXT

  • SmallIntegerSHORT

String

代码示例

Field 示例

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

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))