[Zope] Python script calling environment

Chris McDonough chrism@zope.com
Sun, 14 Jul 2002 13:48:08 -0400


The script is finding the "actions" folder in "activity" instead of
finding it at the root (but you probably guessed that already).  There
would be a huge number of namespaces to search if Zope "kept going"
when it failed to find "action1" in "activity.actions" which would
slow down attribute access tremendously, which is why it doesn't find
"actions.action_1".

Try something like this to search both namespaces:

name_to_find = 'action_1'
actions = getattr(container, 'actions')
if not hasattr(actions, name_to_find):
    actions = context.restrictedTraverse('/actions')

action = getattr(actions, name_to_find)
action()


----- Original Message -----
From: "p.t." <p.training@tin.it>
To: <zope@zope.org>
Sent: Sunday, July 14, 2002 11:26 AM
Subject: [Zope] Python script calling environment


> I have this situation:
>
> root
>     |
>     |- actions (Folder)
>     |     |- action_1 (Script)
>     |
>     |- activity (Folder)
>           |- aScript (Script) => running this script
>           |- actions (Folder)
>                 |- action_2 (Script)
>
> If in aScript I call container.actions.action_1(), testing the
script I get:
>
> Error Type: AttributeError
> Error Value: action_1
>
> I expected that, if "actions.action_1" was not found in "activity",
it was
> searched in the parent folder of "activity", and so on up to the top
of the
> tree.
>
> Is this a simple limitation rule, or there is a deeper reason?
> As an alternative, is there a way to "inherit" in "activity/actions"
the
> scripts contained in "root/activity"?
>
> p.t.
>
>
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
>