[Zope-dev] Zope 2.7.2, restrictedTraverse or hasattr
Dieter Maurer
dieter at handshake.de
Mon Aug 2 16:41:47 EDT 2004
Kai Hoppert wrote at 2004-8-2 14:04 +0200:
>i actually have a Problem with restrictedTraverse and hasattr.
>
>Object1
> Object2
> Object3
>
>
>I want to test if there exists a Object in Object3 wich has the same id and meta type how Object2 (id=myobject).
>so i ask
>
>Object3.restrictedTraverse('myobject',None) or
>
>hasattr(Object3,'myobject')
>
>i every time get's true back.
You can write a Script(Python) "hasattr_unacquired"
with parameters "obj, attr" and body
return hasattr(obj.aq_inner.aq_explicit, attr)
Note that a solution without the "aq_inner" will often work
but is not reliable...
--
Dieter
More information about the Zope-Dev
mailing list