----- Original Message ----- From: "Michael Casaday" <meeper@innerverse.com> Subject: [Zope] Script (Python) function definitions
Defining functions within Script (Python) methods doesn't seem to work very well...
def funcA(): print "<p>Hello, from funcA()!</p>"
def funcB(): print "<p>Hello, from funcB()! I also have a message from funcA()...</p>" funcA()
funcB() return printed
From: "Evan Simpson" <evan@4-am.com>
Script bodies aren't like Python modules; They are function bodies. The most direct translation of what you wrote into plain Python is:
def myScript(): def funcA(): print "<p>Hello, from funcA()!</p>"
def funcB(): print "<p>Hello, from funcB()! I also have a message from funcA()...</p>" funcA()
funcB() myScript()
From: "Dieter Maurer" <dieter@handshake.de>
This will change with Python 2.1 nested scope support.
From: "Paul Winkler" <slinkp23@yahoo.com>
For python < 2.1 (i.e. zope < 2.4), you can get what you want if you pass funcA to funcB, like this:
def funcB(funcA=funcA):
Thanks for all the help! In addition to your comments, it should be noted that (unless you are dumb like me and insist on doing otherwise *grin*) instead of defining the functions in the body of a Python script, one can, of course, write separate Python scripts just for those functions. For instance, if funcB (from my example above) were an actual "Script (Python)" object somewhere else on the site, you could call it by using container.path.to.funcB(). funcB could then successfully call to funcA, which is another separate "Script (Python)" object, by using the same syntax: container.path.to.funcA() _______________ meeper