a question on external method arguments
I'd like to use an external Python method to reference it's caller's object id. Broken down to the simplest example: def testid(self, idref): """test scoping of variables""" return idref which is supposed to return its input argument "idref" unchanged. This works nicely when called from a DTML method, but when I call this external method from a DTML document, something weird happens. DTML source: <p> This is the <!--#var id--> Document.<br> My id is reported to be:<dtml-var "testid(id)"><br> <dtml-let myid=id> but also:<dtml-var "testid(myid)"><br> </dtml-let> </p> gives the following result: <p> This is the sub1-1 Document.<br> My id is reported to be:<Python Method object at 8451b20><br> but also:sub1-1<br> </p> Can anybody explain to me, why I need to copy the "id" variable to a locally scoped "myid" for this to work? And what is the logic that makes the external method return self instead of its input argument? And, of course, I'd like to get to the "id" value through self instead of using an ugly hack like passing an explicit id, which I'm only using for debugging purposes right now. Got to understand where self comes from in an external method, first :-(. :*CU# -- *** Guido A.J. Stevens *** mailto:gyst@nfg.nl *** *** Net Facilities Group *** tel:+31.43.3618933 *** *** http://www.nfg.nl *** fax:+31.43.3560502 ***
Hi Guido,
"Guido" == Guido A J Stevens <gyst@nfg.nl> writes:
Guido> I'd like to use an external Python method to reference it's Guido> caller's object id. Broken down to the simplest example: Guido> Can anybody explain to me, why I need to copy the "id" Guido> variable to a locally scoped "myid" for this to work? And Guido> what is the logic that makes the external method return Guido> self instead of its input argument? I think You actually did more than just copy the 'id'. In a "DTML Document" id is a "method" that needs to be called to get the actual id. I believe that when you say let x=y Zope checks to see if 'y' is callable, and if so, it is called and 'x' is set to be the result of that invocation. try: <p> This is the <!--#var id--> Document.<br> My id is reported to be:<dtml-var "testid(id())"><br> </p> and see if that works for you. -steve
participants (2)
-
gyst@nfg.nl -
Steve Spicklemire