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—Global ID
  • Guid—Guid
  • Integer—整数(长整型)
  • OID—对象 ID
  • Raster—栅格
  • Single—单精度(浮点型)
  • SmallInteger—小整数(短整型)
  • String—字符串(文本)
注:

尽管 Field 对象的 type 属性值与添加字段工具的 field_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))

相关主题