what is this error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shahram555
    New Member
    • Aug 2014
    • 4

    what is this error?

    Code:
    c={'a':1,'b':2}
    c.has_key('a')
    Traceback (most recent call last):
    File "<pyshell#3 2>", line 1, in <module>
    c.has_key('a')
    AttributeError: 'dict' object has no attribute 'has_key'


    Why does this fail?
    Last edited by bvdet; Aug 13 '14, 11:24 AM. Reason: Spelling, clarify question
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Code:
    >>> c={'a':1,'b':2}
    >>> c.has_key('a')
    True
    I can't explain it. 'has_key' is a read-only attribute of a dict object.

    Comment

    • dwblas
      Recognized Expert Contributor
      • May 2008
      • 626

      #3
      What version of Python are you useing? has_key() was removed in Python3.x I think. Use "in",

      Code:
      c={'a':1,'b':2}
      print 'a' in c

      Comment

      Working...