Non hashable object (without __dict__)


Arthur Mc Coy


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.


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question