ArcPy contains a ListFields method, which:
Lists the fields in a feature class, shapefile, or table in a specified dataset.
The resulting object has a count
method, but I can't see how to return the field count from this (shouldn't this return an integer?).
Aside from iterating through the fields and incrementing a counter, how can I return the field count?
import arcpy
fields = arcpy.ListFields(<table>)
count = fields.count
[Dbg]>>> count
<built-in method count of list object at 0x0EDEABE8>
1 Answer 1
To count the number of items in any list (including a list of fields) you can use the Python len
function.
For example:
print len(fields)
count = len(fields)
or
print len(arcpy.ListFields(<table>))
count = len(arcpy.ListFields(<table>))