Functions in a python script
Hi, I found a strange behaviour for a small script that runs correctly in pure Python: == SNIP == foo = 'a great text' def bar(): # error below return foo return bar() ==/SNIP== It makes a "NameError" on "foo" !!! If the first line of bar() is "global foo", this does not change anything. How to use python functions inside Zope python scripts ? Is it reserved for External methods ? Should I provide all "globals" as arguments to the function ?
foo = 'a great text'
def bar(): # error below return foo
return bar() ==/SNIP== It makes a "NameError" on "foo" !!! If the first line of bar() is "global foo", this does not change anything.
How to use python functions inside Zope python scripts ? Is it reserved for External methods ? Should I provide all "globals" as arguments to the function ?
Python scripts are secretly made into functions themselves, and with Python < 2.1 you can't do a def inside a def. That's fixed in Python 2.1, which Zope 2.4 requires. See the thread starting with http://lists.zope.org/pipermail/zope/2001-July/094909.html for more details and a work-around. --jcc (embedding)
participants (2)
-
Gilles Lenfant -
J. Cameron Cooper