Tonight as usual. Open Aptana write Python program, a Has_key call error, the code is as follows:
| The code is as follows |
Copy Code |
info = {} Info.has_key ("key") Console: Traceback (most recent call last): File "D:\workspace\aptana\test\main.py", line 8, in <module> Print (Info.has_key ("email")) www.111cn.net Attributeerror: ' Dict ' object has no attribute ' Has_key ' |
That the Dictionary object does not has_key this attribute? At first I thought it was the computer's nerves, run a few more times, or report this error. It seems that the computer is no problem, in the carefully read the program, a little problem is not AH! Did you think it would be an error because info didn't have members? It's not possible, but I've added a member to info:
| The code is as follows |
Copy Code |
info = {"Key": "Key"} Print (Info.has_key ("key")) )
|
The result is the same hint. The Dictionary object did not has_key this attribute, so I got the command line running and ran through it?
| The code is as follows |
Copy Code |
D:\python27>python.exe D:\workspace\aptana\test\main.py True
|
Is seriously depressed, is aptana in the pydev of the wrong? But other statements, such as if. else.. While...def ... Class.. Import and so on are no problem, why can't we use Has_key? Finally I decided to print the Python version to see:
| The code is as follows |
Copy Code |
Import Sys Print (sys.version) |
Console:
| The code is as follows |
Copy Code |
3.3.4 (v3.3.4:7ff62415e426, Feb 2014, 18:13:51) [MSC v.1600-bit (AMD64)]
|
Python3 version, print python version under cmd:
| The code is as follows |
Copy Code |
D:\python27>python.exe-v Python 2.7.5 |
Python2 version, does it mean that the Python3 version removes Has_key This function I use most often? To the official website to find out, found the following passage:
Removed:apply (). Instead of apply (f, args) use F (*args).
Removed callable (). Instead of callable (f) You can use Isinstance (f, collections. Callable). The operator.iscallable () function is also gone.
Removed coerce (). This function no longer serves a purpose the now classic classes are.
Removed execfile (). Instead of execfile (FN) use EXEC (open (FN). read ()).
Removed the file type. Use Open (). There are now several different kinds of streams, which open can return in the IO module.
Removed reduce (). Use Functools.reduce () if you really need it; However, percent of the time a explicit for loop are more readable.
Removed reload (). Use Imp.reload ().
removed. Dict.has_key () –use the in operator instead.
This is really a trick, but fortunately no waste too much time, did not put the editor, System reload, the last view when the project was created using the interpreter is Python3 version: