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 |
限制返回的结果。如果未指定某一值,则返回所有值。通配符不区分大小写。
(默认值为 None) |
* |
||||||
|
field_type |
Specifies the field type that will be returned.
(默认值为 All) |
String |
返回值
| 数据类型 | 说明 |
|---|---|
|
Field |
返回包含 |
代码示例
列出字段属性。
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}")
生成字段名称列表。
import arcpy
featureclass = "c:/data/municipal.gdb/hospitals"
field_names = [f.name for f in arcpy.ListFields(featureclass)]