[Zope] Another newby question about referring to the value of variables

Dieter Maurer dieter at handshake.de
Mon Jan 26 13:37:03 EST 2004


John Grey wrote at 2004-1-26 13:13 +0000:
> ...
>I am now trying to create a simple product which clones a
>tinytableplus.  I have set it up similarly to the zoo exhibit example
>in the Zope book.
>
>apart from the stuff to redirect back, the add script includes only
>
>  newgrid=context.manage_clone(container[source],id)
>
>where 'source' is a parameter passed from an 'add form' to determine
>which of several tinytables to use (these are in the product folder).
>
>This works if I try to add the product to the product folder itself
>by viewing and submitting the add form that calls the script but when
>I try to use the normal add product drop down list I get this error:
>
>  Error Type: AttributeError
>  Error Value: __getitem__
>
>Everything works OK if I substitute the actual name of a tinytable
>(preceded by .) like this.
>
>    newgrid=context.manage_clone(container.grid,id)

You should have used the "standard" way for computed attribute
access (--> "getattr"). Instead, you decided to use a special
case: the subscription syntax ("obj[id]").
This is only provided by "Folder" instances.
However, when you use "dest/manage_addProduct/ProductName/constructor",
then the "container" of "constructor" is a product dispatcher
instance. This is not a "Folder".
"getattr" would have worked through acquisition.

As a general rule: go for the standard way; use a non-standard
one only when you know what you do.
You can forget about computed attribute access through subscription
syntax.

-- 
Dieter



More information about the Zope mailing list