Can I get a python object from its memory address?

Erotemic picture Erotemic · Apr 1, 2013 · Viewed 11k times · Source

I'm learning how to use Qt with PyQt, and I have a QTabelView with a StandardItemModel I've populated the model successfully and hooked up the itemChanged signal to a slot. I'd l'd like to mess around with whatever object is returned in IPython, so currently I have the line:

def itemChangedSlot(epw, item):
    new_data = item.data()
    print new_data
    print item

which prints

<PyQt4.QtGui.QStandardItem object at 0x07C5F930>
<PyQt4.QtCore.QVariant object at 0x07D331F0>

In the IPython session is it possible to get the object using this memory address? I'm not seeing anything on Google, maybe I don't have my terminology right?

Answer

Raymond Hettinger picture Raymond Hettinger · Apr 1, 2013

You need to hold a reference to an object (i.e. assign it to a variable or store it in a list).

There is no language support for going from an object address directly to an object (i.e. pointer dereferencing).