Synthèse
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.
Syntaxe
ListFields (dataset, {wild_card}, {field_type})
Paramètre | Explication | Type de données | ||||||
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.
(La valeur par défaut est None) | String | ||||||
field_type | Specifies the field type that will be returned.
(La valeur par défaut est All) | String |
Exemple de code
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(f"{field.name} has a type of {field.type} with a length of {field.length}")
Generate a list of field names.
import arcpy
featureclass = "c:/data/municipal.gdb/hospitals"
field_names = [f.name for f in arcpy.ListFields(featureclass)]
Rubriques connexes
Vous avez un commentaire à formuler concernant cette rubrique ?