[ZODB-Dev] Re: getting the object ID (_p_oid attribute)
Florent Guillaume
fg at nuxeo.com
Mon Jun 26 15:16:00 EDT 2006
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
>>> '\x00\x00\x00\x00\x00\x00\x00\x08'
>>> >>> print p._p_oid
>>> >>> p._p_oid is None
>>> False
>>
>> 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
> else:
> 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)
And you can ditch the aq_base if you don't use acquisition-based
classes.
Florent
--
Florent Guillaume, Nuxeo (Paris, France) Director of R&D
+33 1 40 33 71 59 http://nuxeo.com fg at nuxeo.com
More information about the ZODB-Dev
mailing list