[Zope-CMF] Re: Accessing the "context"

Rob Miller ra at burningman.com
Tue Oct 30 15:51:15 EDT 2007


robert rottermann wrote:
> Charlie Clark schrieb:
>> Dear all,
>>
>> a simple question with hopefully a simple answer! How do I access
>> objects from an object's context or hierarchy? Specifically I'd like to
>> be able to access a ZopeDA connection for a site. 
> 
> I
> if you know the id of the object you are looking for beforehand you can
> get it by just requesting it from the context like:
> 
> da = getattr('my_da_or_what_ever', context, None)
> if da:
>   ...
> 

minor nit:

i strongly recommend "if da is not None" rather than just "if da".

if your 'da' object was a containerish object with no contained objects, then 
it would evaluate to False even though the object really existed.  it's 
generally unwise to assume that an object will evaluate to True just because 
it exists.

-r



More information about the Zope-CMF mailing list