Skip to main content

ListFields

Summary

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.

Syntax

ListFields(dataset, {wild_card}, {field_type})

Parameter Explanation Data Type

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.

Use an asterisk (*) to represent zero or more characters. For example, Te* finds Tennessee and Texas.

The default value is None.

String

field_type

Specifies the field type that will be returned.

  • All—All field types are returned. This is the default.

  • Blob—Fields of Blob type are returned.

  • BigInteger—Fields of Big Integer type are returned.

  • Date—Fields of Date type are returned.

  • DateOnly—Fields of Date Only type are returned.

  • Double—Fields of Double type are returned.

  • Geometry—Fields of Geometry type are returned.

  • GlobalID—Fields of Global ID type are returned.

  • Guid—Fields of GUID type are returned.

  • Integer—Fields of Integer type are returned.

  • OID—Fields of Object ID type are returned.

  • Raster—Fields of Raster type are returned.

  • Single—Fields of Single type are returned.

  • SmallInteger—Fields of Small Integer type are returned.

  • String—Fields of String type are returned.

  • TimeOnly—Fields of Time Only type are returned.

  • TimestampOffset—Fields of Timestamp Offset type are returned.

String

Return value

Data Type Explanation

Field

A list containing Field objects is returned.

Code sample

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(f"{field.name} has a type of {field.type} with a length of {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)]