Resumen
Returns a list of fields in a feature class, shapefile, or table in a specified dataset. The returned list can be limited with search criteria for name and field type and will contain field objects.
Sintaxis
ListFields (dataset, {wild_card}, {field_type})
Parámetro | Explicación | Tipo de datos | ||||||
dataset | The specified feature class or table with the fields to be returned. | String | ||||||
wild_card | Limits the results returned. If a value is not specified, all values are returned. The wildcard is not case sensitive.
(El valor predeterminado es None) | String | ||||||
field_type | The specified field type to be returned. The following are valid field types::
(El valor predeterminado es All) | String |
Valor de retorno
Tipo de datos | Explicación |
Field | A list containing Field objects is returned. |
Muestra de código
ListFields example
List field properties.
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 example 2
Generate a list of field names.
import arcpy
featureclass = "c:/data/municipal.gdb/hospitals"
field_names = [f.name for f in arcpy.ListFields(featureclass)]