[C++-sig] dict.has_key works in a Python script, not in C++

Jim Bosch talljimbo at gmail.com
Wed Mar 3 23:56:12 CET 2010


On Wed, 2010-03-03 at 15:35 -0500, Stefan Seefeld wrote:

> >
> > I tried stepping through the code with gdb, but I got lost ... What am 
> > I missing ?  TIA
> 
> Python requires dictionary keys to be immutable. I wouldn't be surprised 
> if it used object identity checks (such as address comparison) instead 
> of a deep equal test, as a faster way to look up objects.
> 

That's exactly what it does, unless your object implements the __hash__
special method.  Do that (and in so doing, promise that the return value
of __hash__ will never change), and this should work.


Jim Bosch




More information about the Cplusplus-sig mailing list