0

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>
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Aug 11, 2014 at 6:35

1 Answer 1

7

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>))
answered Aug 11, 2014 at 6:42
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.