[Zope] Name Error / Global name not defined
J. Cameron Cooper
jccooper at jcameroncooper.com
Mon Sep 29 23:00:36 EDT 2003
>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."
More information about the Zope
mailing list