TypeError: 'dict' object is not callable while using dict( )

前端 未结 3 832
余生分开走
余生分开走 2021-01-18 11:31

I was using Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 , when i ran the folllowing code in it the corresponding error is shown .I searche

3条回答
  •  无人及你
    2021-01-18 12:08

    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 "", line 1, in 
    TypeError: 'dict' object is not callable
    >>> 
    

    As a general rule, one should not use built-in type names as variable names, to prevent this error.

提交回复
热议问题