Hello, I have just realized that the Python wrapper classes will probably not compare as equal even if the underlying C++ class pointers point to the same object. That's what probably is happening in the code below, because the 2nd function uses a key that comes from a different wrapper around the same object.
This must be a common problem with SWIG; does anyone know how to handle it ? Thanks ----- Original Message ----- From: "Chris" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, August 16, 2004 1:24 PM Subject: python keyerror problem ? > Hello, > > I have a C++ class wrapped with swig. I add it as a key in a dictionary as > follows: > > my_key = swigclass() # create class > my_value = another_swigclass() # create 2nd class > my_dict = {} > > my_dict[ my_key] = my_value > > If I print my_dict, it shows the expected key:value pair there. It displays > the wrapped values (i.e. a string with the pointer values and object type > embedded ) > > if I then access the value: > > my_dict[ my_key] > > it gives me the correct object (my_value) as expected > > Then, in another function, I try the same access on the same dictionary, > (again after printing the dictionary contents to make sure it has 'my_key' ) > > my_dict[ my_key] > > this generates a KeyError exception. I have no idea why, since the key is > clearly valid and present in the dictionary. > > If I add a string key:value pair (eg. "test key" : "test value" ) to that > same dictionary, and try to access "test key", that works fine . > > Can anyone help ? > Thanks, > Chris > _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs Other options: http://listserv.ActiveState.com/mailman/listinfo/ActivePython