Typeerror: 'dict' Object Is Not Callable While Using Dict( )
Solution 1:
In a fresh interpreter:
>>> bob=dict(name='bob smith',age=42,pay='10000',job='dev')
>>> bob
{'age': 42, 'pay': '10000', 'job': 'dev', 'name': 'bob smith'}
However, you are getting a TypeError
:
TypeError: 'dict' object is not callable
This error you get tells you that yourdict
is not callable.
Since mydict
is callable when I open a fresh interpreter, it means that yourdict
is different.
Most likely, you defined a dict
variable, which overrode the built-in dict
. Look for the
dict = {...}
line, and rename your variable.
As pointed out by @Robᵩ, don't use built-in names for your variables. Especially avoid the tempting str
, list
, and so on.
Solution 2:
On a previous line in that interactive session, you have rebound the dict
name to some variable. Perhaps you have a line like dict={1:2}
or dict=dict(one=1, two=2)
.
Here is one such session:
>>> dict=dict(one=1)
>>> bob=dict(name='bob smith',age=42,pay='10000',job='dev')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'dict'objectisnotcallable>>>
As a general rule, one should not use built-in type names as variable names, to prevent this error.
Solution 3:
edit: Ignore this, I am told this is bad practice.
As mgilson stated, the issue is likely that you have a variable called dict. The solution to this would be to run
deldict
which deletes the variable by that name.
Post a Comment for "Typeerror: 'dict' Object Is Not Callable While Using Dict( )"