By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,960 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

what is this error?

shahram555
P: 4
Expand|Select|Wrap|Line Numbers
  1. c={'a':1,'b':2}
  2. c.has_key('a')
Traceback (most recent call last):
File "<pyshell#32>", line 1, in <module>
c.has_key('a')
AttributeError: 'dict' object has no attribute 'has_key'


Why does this fail?
Aug 13 '14 #1

✓ answered by dwblas

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

Expand|Select|Wrap|Line Numbers
  1. c={'a':1,'b':2}
  2. print 'a' in c 

Share this Question
Share on Google+
2 Replies


bvdet
Expert Mod 2.5K+
P: 2,851
Expand|Select|Wrap|Line Numbers
  1. >>> c={'a':1,'b':2}
  2. >>> c.has_key('a')
  3. True
I can't explain it. 'has_key' is a read-only attribute of a dict object.
Aug 13 '14 #2

Expert 100+
P: 614
What version of Python are you useing? has_key() was removed in Python3.x I think. Use "in",

Expand|Select|Wrap|Line Numbers
  1. c={'a':1,'b':2}
  2. print 'a' in c 
Aug 13 '14 #3

Post your reply

Sign in to post your reply or Sign up for a free account.