[Zope] Re: Object retrieval syntax
Evan Simpson
evan at 4-am.com
Mon Aug 18 14:03:05 EDT 2003
Michael Long wrote:
> I noticed that if an object's id begins with a numeric character then
> the syntax to retrieve the object must be *container['1']* otherwise the
> syntax to retrive the item may be either *container['myID']* or
> *container.myID*. Why is this?
This is not quite accurate; standard Zope Folders support two methods of
object access which are similar, but not identical.
The first is attribute access, which is what you use when you write
"container.myID" or "getattr(container, 'myID')". Python's syntax
requires that the attribute name in the first expression be a valid
identifier (i.e. start with a letter or underscore, etc). In the second
expression, the attribute's name is provided as a string literal, so
only Zope's object naming constraints apply. In either case, if the
named attribute does not exist in the container, and the container
supports acquisition (which Folders do), then Zope will attempt to fetch
the attribute from the container's context.
The second is item access, as in "container['myID']". As with the
"getattr()" form of attribute access, the item key can be any valid Zope
object name. *Unlike* attribute access, item access will not perform
implicit acquisition if the item key is not found in the container.
Cheers,
Evan @ 4-am
More information about the Zope
mailing list