0

I'm getting the following error "Type Error: 'dict' object is not callable", with the code below:

import arcpy

def printDict(dictionary, printCount=False):
    for key in dictionary:
        arcpy.AddMessage(key + ": " + dictionary[key])
    if printCount is True:
        arcpy.AddMessage(str(len(dictionary)))

pld3GDB = 'C:\\Users\\bro81520\\Documents\\ArcGIS\\PLDV3_SPC_ODN_315_25Sep\\PLDV3_SPC_ODN_315_25Sep.gdb\\WO_HIERARCHY'
fdaAREA = 'C:\\Users\\bro81520\\Documents\\ArcGIS\\Default.gdb\\FDA_AREA'

d = dict()  # VENDOR_WO_ID : NFID

fields1 = ['VENDOR_WO_ID', 'NFID', 'ISFDA'] 
with arcpy.da.SearchCursor(pld3GDB, fields1) as cursor:
    for row in cursor:
        if row[2] == "Y":
            d[row[0]] = row[1]

# print dictionary
printDict(d, printCount=True)

fields2 = ['bv_workorderid', 'bv_nfid']
with arcpy.da.UpdateCursor(fdaAREA, fields2) as cursor:
    for row in cursor:
        if row[0] in d:
            row[1] = d[row[0]]
            cursor.updateRow(row)           

I've looked at the following resources, but haven't deciphered exactly what is wrong: https://stackoverflow.com/questions/41605525/typeerror-dict-object-is-not-callable-while-using-dict

https://gis.stackexchange.com/questions/198770/creating-a-dict-with-search-cursor

6
  • Is that your entire code? Have you used dict anywhere else in your code?
    – Thomas
    Commented Oct 23, 2018 at 17:15
  • I added the rest of my code in, figured the beginning part was pretty trivial.
    – GIS_GOD
    Commented Oct 23, 2018 at 18:07
  • 1
    Does your code work as expected using d = {}?
    – phloem
    Commented Oct 23, 2018 at 18:16
  • If I change that I get "Parsing error SyntaxError: invalid syntax (line 12)"
    – GIS_GOD
    Commented Oct 23, 2018 at 18:17
  • 1
    Hmmm... d = {} should be valid syntax
    – phloem
    Commented Oct 23, 2018 at 18:21

2 Answers 2

3

I suspect somewhere along the way, the built-in dict() got set to something else (probably like below), and is no longer the object you think it is.

d = dict()        # new dictionary
print(d)          # it works!

{}    

dict = {}         # dict isn't dict() anymore
d = dict()        # error!

TypeError                                 Traceback (most recent call last)
<ipython-input-12-e3c238d66cd2> in <module>
----> 1 d = dict()

TypeError: 'dict' object is not callable
0

This error is generated when we try to call a dictionary using invalid methods. As shown in the example below.

Example:

# Creating dictionary 'MyDict'
MyDict= {
'car' : 'Honda city',
'type': 'sedan',
'color' : 'Blue'
}

# Printing Dictionary
print(MyDict())

# Checking length of dictionary
print("length of the dictionary :",len(MyDict))

Output:

File "nterror.py", line 9, in <module>
print(MyDict( ))
TypeError: 'dict' object is not callable

Read here in details

Your Answer

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

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