The zope way to do it
I started playing with external methods, because I have to display quite complex data (stored in dictionaries of lists of dictionaries) that differs on a per directory basis. In plain python I'd put all the functions I need in a file like this one, called test_aux.py -------------------------------------------- def display(text): result='' for word in text: result= result + word + ' ' return result -------------------------------------------- then I'd create another file that imports display from test_aux.py and uses it, say test.py: -------------------------------------------- from test_aux import display print display(['This','is','a','very','simple','example.']) -------------------------------------------- and the run it with 'python test.py' What's the python way to do this? Ragnar
I started playing with external methods, because I have to display quite complex data (stored in dictionaries of lists of dictionaries) that differs on a per directory basis.
In plain python I'd put all the functions I need in a file like this one, called test_aux.py -------------------------------------------- def display(text): result='' for word in text: result= result + word + ' ' return result -------------------------------------------- then I'd create another file that imports display from test_aux.py and uses it, say test.py: -------------------------------------------- from test_aux import display print display(['This','is','a','very','simple','example.']) -------------------------------------------- and the run it with 'python test.py'
What's the python way to do this?
Oops! Silly mistake! Should be: What's the ZOPE way to do this?
Ragnar
The Zope way to do this is no different, save for the fact that each function that you want to call from Zope needs to be made into an external method. You make external methods by putting Python modules in the Extensions directory of your Zope install and using the management interface to add an External method. You will need to name your external method. This name can be the same as the function name you're trying to call or it could be something completely different, that's up to you. Usually, I like to name external methods beginning with an "em", so I'd probably name my external method in this case "emDisplay." The external method edit dialog will ask you for a function name and a module name. The function name is the name of the actual Python function you'd like to call from Zope. The module name is the module in which the function lives. In your example, you'd want to specify the function as "display", loaded from module "test_aux". Then in Zope, you'd set up a DTML method or document (we'll call it dtDisplay) that has this in it: <dtml-var standard_html_header> <h1>My Example Code</h1> <dtml-var "emDisplay('This', 'is', 'a', 'very', 'simple', 'example')"> <dtml-var standard_html_footer> So then when you call dtDisplay from the web, like: http://mysite.com/dtDisplay It should show: My Example Code This is a very simple example Ragnar Beer wrote:
I started playing with external methods, because I have to display quite complex data (stored in dictionaries of lists of dictionaries) that differs on a per directory basis.
In plain python I'd put all the functions I need in a file like this one, called test_aux.py -------------------------------------------- def display(text): result='' for word in text: result= result + word + ' ' return result -------------------------------------------- then I'd create another file that imports display from test_aux.py and uses it, say test.py: -------------------------------------------- from test_aux import display print display(['This','is','a','very','simple','example.']) -------------------------------------------- and the run it with 'python test.py'
What's the python way to do this?
Oops! Silly mistake! Should be: What's the ZOPE way to do this?
Ragnar
_______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
-- Chris McDonough Digital Creations, Inc. Zope - http://www.zope.org
participants (2)
-
Chris McDonough -
Ragnar Beer