Hi, Im getting an error in a DTML document while trying to access an array I declared in a python script which I subsequently returned. The python script looks like: # Creates a pending array pendingArray = ['test'] return pendingArray and is called by this line in the DTML document. <dtml-call expr="createPendingArray()"> The line that is causing the error to be thrown is: <dtml-call expr="addEntryPendingArray(pendingArray,Word)"> which causes the following error: Error Type: NameError Error Value: global name 'pendingArray' is not defined Any help in this matter would be greatly appreciated.. Thanks in advance.. __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
Sandeep Chopra wrote:
Hi, Im getting an error in a DTML document while trying to access an array I declared in a python script which I subsequently returned.
The python script looks like:
# Creates a pending array
pendingArray = ['test'] return pendingArray
and is called by this line in the DTML document. <dtml-call expr="createPendingArray()">
The line that is causing the error to be thrown is:
<dtml-call expr="addEntryPendingArray(pendingArray,Word)"> which causes the following error:
Error Type: NameError Error Value: global name 'pendingArray' is not defined
Any help in this matter would be greatly appreciated.. Thanks in advance..
__________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
try this: 1: <dtml-let pendingArray="createPendingArray()"> ... <dtml-call expr="addEntryPendingArray(pendingArray,Word)"> ... </dtml-let> cheers, bernd
The python script looks like:
# Creates a pending array
pendingArray = ['test'] return pendingArray
and is called by this line in the DTML document. <dtml-call expr="createPendingArray()">
The line that is causing the error to be thrown is:
<dtml-call expr="addEntryPendingArray(pendingArray,Word)"> which causes the following error:
Error Type: NameError Error Value: global name 'pendingArray' is not defined
There's a suitable answer out there, but I thought I'd get a little deeper on this. Your Python script isn't executed in the namespace of the DTML document. Which is to say, 'pendingArray' is local--visible only to the script during its execution--and disappears from the universe as soon as the script finshes. Only the result is available to the caller: the DTML method, and if nothing is done with it, it goes poof. If you want the result of that script (a list) available in the DTML, you have to put it in the DTML namespace somehow, which is what the dtml-let solution did. You could also use the result like:: <dtml-call expr="addEntryPendingArray(createPendingArray(),Word)"> Here the result of 'createPendingArray' is available to the 'addEntryPendingArray' method as an argument. After that method completes, the result (the value of the list originally assigned to 'pendingArray') is again lost to the ether. --jcc -- "My point and period will be throughly wrought, Or well or ill, as this day's battle's fought."
participants (3)
-
Bernd Dorn -
J. Cameron Cooper -
Sandeep Chopra