473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

what is this error?

shahram555
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 

2 1286
bvdet
2,851 Expert Mod 2GB
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
dwblas
626 Expert 512MB
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

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

Similar topics

3
by: paul dallaire | last post by:
HI! I have a readme that gives the following statement. Requirements PHP3 or PHP4: PHP also needs to be compiled with MySQL support; MySQL (tested with 3.21.x, 3.22.x, 3.23.x and 4.0.x); A...
29
by: asj | last post by:
Can you guess what this is? http://www.blueboard.com/phone/apache_sept_2003.gif It's a history of the IIs "Titanic", which is being slowly and painfully sunk by the open source Apache web...
12
by: craig | last post by:
Quick question for the experts... Whenever I set the Image property of a PictureBox on one of my windows forms to a PNG graphic file on my hard drive, I get the following runtime error when I...
4
by: mistral | last post by:
Can anyone help to identify what this encryption used in this script? <html> <body> <script type="text/javascript" language="JavaScript"> function decrypt_p(x){ var l=x.length, b=1024,...
3
by: manjuks | last post by:
HI All, Can any one please let me know what this for loop is trying to do for V in ${MYVERSION:-"$VERSION"} what :- stands for? I dont understand this condition, Can any one help me please?...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.