deprecation of has_key?

Steve Holden steve at holdenweb.com
Thu Apr 21 05:43:36 EDT 2005


nicksjacobson at yahoo.com wrote:
> I haven't heard of any plans to deprecate the dictionary has_key
> method, as the "in" keyword makes it obsolete.
> 
> i.e.
> if key in dict:
> 
> instead of
> if dict.has_key():
> 
> 
> Is there some reason to keep has_key?
> 
Two words: backward compatibility. To lose that method now would break 
thousands of existing programs. The 2.4 library would probably 
experience breakage too ... let's see:

$ find /lib/python2.4/ -name "*.py" -exec grep has_key {} \; | wc -l
587

Oops!

The method might disappear in Python 3.0, when we will be allowed to 
break backward compatibility - you are correct in saying it's no longer 
necessary.

regards
  Steve
-- 
Steve Holden        +1 703 861 4237  +1 800 494 3119
Holden Web LLC             http://www.holdenweb.com/
Python Web Programming  http://pydish.holdenweb.com/




More information about the Python-list mailing list