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)

String
field_type

Specifies the field type that will be returned.

  • All All field types are returned. This is the default.
  • BlobFields of Blob type are returned.
  • BigIntegerFields of Big Integer type are returned.
  • DateFields of Date type are returned.
  • DateOnlyFields of Date Only type are returned.
  • DoubleFields of Double type are returned.
  • GeometryFields of Geometry type are returned.
  • GlobalIDFields of Global ID type are returned.
  • GuidFields of GUID type are returned.
  • IntegerFields of Integer type are returned.
  • OIDFields of Object ID type are returned.
  • RasterFields of Raster type are returned.
  • SingleFields of Single type are returned.
  • SmallIntegerFields of Small Integer type are returned.
  • StringFields of String type are returned.
  • TimeOnlyFields of Time Only type are returned.
  • TimestampOffsetFields 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)]

相关主题