I am trying to get the features count from feature, then put it in a dictionary that I can call later:

ct_dict = dict()
fipsList = ['13245','06007']
for fip in fipsList: 
    mergedJoinCentroids = C:/Workspace/Sandbox/MapChangeProject/selects.gdb/mergeJoinCentroids_{}".format(fip)
    property_ct = str(arcpy.GetCount_management(mergedJoinCentroids))
    ct_dict.setdefault(fip, property_ct)

I tried to make a simple function that I could then easily import into another script:

def ct_dict():
   return ct_dict

This should return a dictionary that looks like this {'13245': '72456', '06007': '93557'}.However, I run the other script with the ct_dict() function, I get an error: AttributeError: 'function' object has no attribute 'items':

import <script name>
from <script name> import ct_dict
counts = ct_dict()
for k, v in ct_dict.items():
    if fip == v:
       sheet1.write(r, propertyCol, v)

So, basically, it is just returning something like this <function FEMA_WMS_3.ct_dict()>, not a dictionary. How do I resolve this?


Looks like you want to create and object instead of a function. When you're looking for ct_dict.items() it's going to the function ct_dict and looking for a items() method. There isn't one.

It should be;

for k, v in counts.items():
   if fip ==v:

Not the answer you're looking for? Browse other questions tagged or ask your own question.