[Zope] Object method calling rules

Jim Fulton jim@digicool.com
Fri, 28 May 1999 10:01:34 -0400


TFE MMS JARVIS JOHN wrote:
> 
> Hi all,
> After being pulled away for a bit, I'm finally back to Zopeing. Yay!
> 
> I know this is explained somewhere, but I can't seem to find where...
> 
> I have a Product that looks something like:
> 
> class myProduct(
> ...
> )
> ...
> 
>     view_html=HTMLFile('viewProduct',globals())
> ...
>     def __call__(self,REQUEST=None):
>         return self.view_html(self,REQUEST)
> ...
> 
> So I can use <!--#var myObjectInst--> to render it.
> I can also use <!--#call "myObjInst.aMethod()"--> to call a method.
> 
> My objects have part numbers of the form 'xxx-xxxxx-xx' as id's, so
> they have to be expressed as _['xxx-xxxxx-xx'] in python expressions.
> What I don't understand is why <!--#call "_['myObjInst'].aMethod()"-->
> returns an error: 'string' object has no attribute 'update_properties'
> By searching my mail archive, I found that I can use
> _.getitem('myObjInst',0)
> so that <!--#call "_.getitem('myObjInst',0).aMethod()"--> works.
> 
> My question: what is the difference between myObjInst and _['myObjInst']?
>  _['myObjInst'] calls the __call__ method?

Right.  The __getitem__ operator on the namespace object, _, tries to call
the object.  _.getitem(name, 0) doesn't call the object.  The second argument
indicates whether the object should be called.  This is a little unfortunate and
a bit hard to fix, for both technical and backward compatibility reasons.
 
> Pointers to pertinent documentation would be greatly appreciated (I
> know it exists--I've read it once before :^)

This *should* be documented in the discussion of the _ variable in the DTML 
manual .... e gads it is! ;)

See: http://www.zope.org/Documentation/Guides/DTML/DTML-HTML/DTML.html#pgfId-507695

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.