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?

closed as off-topic by ahmadhanb, Mark Ireland, Vince, Jochen Schwarze, Andre Silva Sep 28 '18 at 18:09

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions relating to general IT or with no clear GIS component, are off-topic here but can be researched/asked at Stack Overflow (software development), Super User (computing hardware and software), Database Administrators (relational databases) and other SE sites" – ahmadhanb, Mark Ireland, Vince, Jochen Schwarze, Andre Silva
If this question can be reworded to fit the rules in the help center, please edit the question.


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.