Skip to main content

ListFields

汇总

可返回指定数据集中的要素类、shapefile 或表中的字段的列表。 返回的列表可用针对名称和字段类型的搜索条件进行限制,并将包含 Field 对象。

语法

ListFields(dataset, {wild_card}, {field_type})

参数 说明 数据类型

dataset

The specified feature class or table with the fields to be returned.

String

wild_card

限制返回的结果。如果未指定某一值,则返回所有值。通配符不区分大小写。

符号

说明

示例

*

表示零个或多个字符。

Te* 可找到田纳西州和德克萨斯州。

(默认值为 None)

*

field_type

Specifies the field type that will be returned.

  • All— All field types are returned. This is the default.

  • Blob—Fields of Blob type are returned.

  • BigInteger—Fields of Big Integer type are returned.

  • Date—Fields of Date type are returned.

  • DateOnly—Fields of Date Only type are returned.

  • Double—Fields of Double type are returned.

  • Geometry—Fields of Geometry type are returned.

  • GlobalID—Fields of Global ID type are returned.

  • Guid—Fields of GUID type are returned.

  • Integer—Fields of Integer type are returned.

  • OID—Fields of Object ID type are returned.

  • Raster—Fields of Raster type are returned.

  • Single—Fields of Single type are returned.

  • SmallInteger—Fields of Small Integer type are returned.

  • String—Fields of String type are returned.

  • TimeOnly—Fields of Time Only type are returned.

  • TimestampOffset—Fields of Timestamp Offset type are returned.

(默认值为 All)

String

返回值

数据类型 说明

Field

返回包含 Field 对象的列表。

代码示例

ListFields 示例

列出字段属性。

import arcpy

# For each field in the Hospitals feature class, print
# the field name, type, and length.
fields = arcpy.ListFields("c:/data/municipal.gdb/hospitals")

for field in fields:
    print(f"{field.name} has a type of {field.type} with a length of {field.length}")
ListFields 示例 2

生成字段名称列表。

import arcpy

featureclass = "c:/data/municipal.gdb/hospitals"
field_names = [f.name for f in arcpy.ListFields(featureclass)]