ListFields (arcpy)

摘要

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

语法

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

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

String
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.
  • BLOB —Only field types of BLOB are returned.
  • Date —Only field types of Date are returned.
  • Double —Only field types of Double are returned.
  • Geometry —Only field types of Geometry are returned.
  • GlobalID —Only field types of GlobalID are returned.
  • GUID —Only field types of GUID are returned.
  • Integer —Only field types of Integer are returned.
  • OID —Only field types of OID are returned.
  • Raster —Only field types of Raster are returned.
  • Single —Only field types of Single are returned.
  • SmallInteger —Only field types of SmallInteger are returned.
  • String —Only 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.
fieldList = arcpy.ListFields("C:/Data/Municipal.gdb/Hospitals")

for field in fieldList:
    print("{0} is a type of {1} with a length of {2}"
          .format(field.name, field.type, field.length))
ListFields 示例 2

生成字段名称列表。

import arcpy

fclass = "C:/Data/Municipal.gdb/Hospitals"
fieldnames = [f.name for f in arcpy.ListFields(fclass)]

相关主题

9/15/2013