ListFields

Récapitulatif

Lists the 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ètreExplicationType de données
dataset

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

String
wild_card

Un caractère générique limite les résultats renvoyés. Si aucun caractère générique n'est spécifié, toutes les valeurs sont renvoyées.

(La valeur par défaut est 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.
  • DateOnly field types of Date are returned.
  • DoubleOnly field types of Double are returned.
  • GeometryOnly field types of Geometry 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.

(La valeur par défaut est All)

String
Valeur renvoyée
Type de donnéesExplication
Field

A list containing Field objects is returned.

Exemple de code

ListFields example

List field properties.

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 example 2

Generate a list of field names.

import arcpy

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

Rubriques connexes


7/10/2012