Non hashable object (without __dict__)

Arthur Mc Coy 1984docmccoy at gmail.com
Wed Apr 20 09:07:21 EDT 2011


Hello,


I have a C++ application, I used SWIG to call the python code. I pass
myModule.myObject object to the method of python code and what to
store it in JSON format.

The problem is when I do:

o = myModule.myObject()


inside python, the o object has __dict__ property, but if I take the
passed object o like:

def myMethod(self, objects):
    for o in objects:
        print o.__dict__


it fails saying no SwigPyObject does not have __dict__ property. The
only way to use o properties is to call it by name like here:

print o.MyProperty


But in order to use json.dump( objects, file, default =
self.MyJSONEncode ) I MUST to pass to MyJSONEncode method an object
that has __dict__ as its property.



So, what is the best way to correct my objects, which are coming from C
++ code to make them available for putting in JSON format ?


Thank you.



More information about the Python-list mailing list