[Zope] indirect calling of methods with parameters

Casey Duncan cduncan@kaivo.com
Tue, 27 Mar 2001 11:04:20 -0700


Bernd Worsch wrote:
> 
> On Tue, Mar 27, 2001 at 09:23:53AM -0700, Casey Duncan wrote:
> >
> > <dtml-var expr="_.getitem(method)(params)">
> >
> > If you wanted the parameter list to be variable as well, you could try
> > passing a dictionary like so:
> >
> > <dtml-let params="{'arg1':value1, 'arg2':value2, ...}">
> >     <dtml-var expr="_.getitem(method)(kw=params)">
> > </dtml-let>
> >
> > The params dictionary could be set anywhere before the actual call or
> > even passed whole as a parameter to the calling method.
> 
> Ahhhh! Ok, i simply didn't recognize that getitem allows to pass parameters.
> This hint provided, i solved my problem like this:
> 
> <dtml-let method="'SomeMethod'"
>           para1="'FirstArgument'"
>           para2="'SecondArgument'">
>    <dtml-var expr="_.getitem(method)(para1, para2)"><br>
> </dtml-let>
> 
> I somehow failed to achive the same by using a parameter dictionary as
> you suggested. Nevertheless i'm REALLY grateful for you braking my deadlock
> of thought! Btw i couldn't find to many docs on using getitem like this!
> Could be i was to dumb looking for it, but i'm quite sure it is neither
> in Zope Book nor in the Howto on Advanced Scripting. (Not to mention
> the online help). I'll be preparing a supplement and try not include
> to much nonsense. If anybody whishes to review or contribute i could
> put the supplement on zwiki.org before sending it to someone to add it
> to the documentation.
> 

The critical difference is the _[name] calls the object (if it is
callable) first before returning the result whereas _.getitem(name) does
not, it simply returns the method object itself.

I believe this is mentioned in Dieter's book, along with many other
extremely helpful tidbits.

BTW: you could shorten the above code to just:

<dtml-var expr="_.getitem(method)(para1='FirstArgument',
para2='SecondArgument')"><br>
-- 
| Casey Duncan
| Kaivo, Inc.
| cduncan@kaivo.com
`------------------>