On Jun 26, 2006, at 3:16 PM, Florent Guillaume wrote:

On 26 Jun 2006, at 21:11, Robert Gravina wrote:
On 2006/06/27, at 3:49, Benji York wrote:
Robert Gravina wrote:
I just tried loading a persisted object interactively and noticed that although the _p_oid doesn't print out as anything (and hence I always thought it was empty in my debugging prints), it isn't actually None! Can anyone explain this? (here "p" is my persisted object)
 >>> p._p_oid
 >>> print p._p_oid
 >>> p._p_oid is None

What would you expect to see if you printed out seven null characters and a backspace?

Hahaha - that's a good point! I was expecting IDs to look, well, something like "asdf23asdf". Well, anyway thankyou! I seemed to have solved this problem. I was able to write a __eq__ function like this:

    def __eq__(self, other):
        if isinstance(other, <name of my class>):
if hasattr(other,"_p_oid") and other._p_oid != None and (other._p_oid == self._p_oid):
                return True
                return False

and now can compare objects for equality after the (Twisted) client edits them and sends them back.

You can shorten that to
def __eq__(self, other):
    return aq_base(self) is aq_base(other)

Heh, good point.

And you can ditch the aq_base if you don't use acquisition-based classes.

(or don't have proxies generally--Zope 3 has a number of them, for instance.)

(this wouldn't work if you had the same persistent object from different connections...but don't go there!)

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to