[Zope3-Users] Re: object id / name / name within parent?

Philipp von Weitershausen philipp at weitershausen.de
Mon Jan 10 07:22:15 EST 2005


Florent Guillaume wrote:
> Petri Savolainen  <petri.savolainen at iki.fi> wrote:
> 
>>Wow I've got a real newbie question here: How does the identification 
>>and naming of objects work in Zope3?
>>
>>I understand that objects have names, stored in the __name__ attribute 
>>of an object, and that this 'name' is what containers know contained 
>>objects by. To what extent is this analogous to a Zope2 id? Or do Z3 
>>objects have an id, in addition to name?
> 
> The name is indeed comparable to Zope 2's id. Except that in Zope 2,
> both an object and its container know the id (which makes for redundant
> information that can get out of sync etc), whereas in Zope 3 the name is
> only stored with the object itself.

Wrong. The container keeps the name, too. Containers are usually simple 
mapping objects (like a dict). The fact that the name is also stored on 
the object is an extra feature that you really shouldn't know about 
because you should use

   >>> zapi.getName(obj)

anyways. That will adapt 'obj' to IPhysicallyLocatable and extract its 
name from wherever the implementation wants to get it from. For most 
persistent objects (or contained proxied ones), this is __name__. It 
doesn't have to be, though.

For retrieving and manipulating contained information (name and 
parents), one should preferrably use the provided machinery, meaning the 
zapi methods (getName, getParent, getParents, etc.) and the 
contained/setitem functions from zope.app.container.contained.

Philipp



More information about the Zope3-users mailing list