[ZODB-Dev] Re: getting the object ID (_p_oid attribute)
Robert Gravina
robert at gravina.com
Mon Jun 26 15:28:04 EDT 2006
>>> 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)
>
> Heh, good point.
>
I assume you're referring to repacing just "isinstance(other, <name
of my class>)"? Actually, to be honest I don't even know what
Acquisition based classes are, so I'm probably not using them. I'm
just subclassing Persistent
>> 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!)
>
Don't worry, I'm happy enough just going this far!
Thanks all for your great and fast help! I've struggled with this on
and off for a couple of days (and it's 4am).. what a relief!
Robert
More information about the ZODB-Dev
mailing list