ListFields (arcpy)

摘要

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

语法

ListFields (dataset, {wild_card}, {field_type})
参数说明数据类型
dataset

The specified feature class or table whose fields will be returned.

String
wild_card

wild_card 可限制返回的结果。如果未指定任何 wild_card,则会返回所有值。

(默认值为 None)

String
field_type

The specified field type to be returned. Valid field types are:

  • All All field types are returned. This is the default.
  • BLOBOnly field types of BLOB are returned.
  • DateOnly field types of Date are returned.
  • DoubleOnly field types of Double are returned.
  • GeometryOnly field types of Geometry are returned.
  • GlobalIDOnly field types of GlobalID are returned.
  • GUIDOnly field types of GUID are returned.
  • IntegerOnly field types of Integer are returned.
  • OIDOnly field types of OID are returned.
  • RasterOnly field types of Raster are returned.
  • SingleOnly field types of Single are returned.
  • SmallIntegerOnly field types of SmallInteger are returned.
  • StringOnly field types of String are returned.

(默认值为 All)

String
返回值
数据类型说明
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("{0} is a type of {1} with a length of {2}"
          .format(field.name, field.type, field.length))
ListFields 示例 2

生成字段名称列表。

import arcpy

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

相关主题

5/10/2014