What is the idiomatic way of expressing utility functions? I.e., python scripts that are meant to be callable by a variety of templates, dtml methods, other python scripts, etc. but which tend to be small, useful, and usually oriented at manipulating data (not generating html). Creating lots of separate Python (Script) objects seems like overkill, yet defined functions inside such a script don't seem to be easily accessible outside the script object. E.g. Script1 --------- def foo(a): return a[0] request= container.REQUEST <blah blah> return container.resultPage() Script2 -------- <blah> container.Script1.foo(x) The call in Script2 doesn't work...I'll go read the source for a script object and see if there's an attribute that gives me the access I'm looking for, but I thought I'd ask the list, too. aathan <Andrew Athan>
you could put them into a single place, e.g. a folder off your zope root directory, so they don't clutter up the ZMI if that's your concern. thee certainly is no problem creating a bunch of python scripts. jens On Wednesday, Nov 6, 2002, at 23:03 US/Eastern, Andrew Athan wrote:
What is the idiomatic way of expressing utility functions? I.e., python scripts that are meant to be callable by a variety of templates, dtml methods, other python scripts, etc. but which tend to be small, useful, and usually oriented at manipulating data (not generating html).
Creating lots of separate Python (Script) objects seems like overkill, yet defined functions inside such a script don't seem to be easily accessible outside the script object.
E.g.
Script1 ---------
def foo(a): return a[0]
request= container.REQUEST
<blah blah> return container.resultPage()
Script2 -------- <blah> container.Script1.foo(x)
The call in Script2 doesn't work...I'll go read the source for a script object and see if there's an attribute that gives me the access I'm looking for, but I thought I'd ask the list, too.
aathan <Andrew Athan>
Jens: Thanks. I'd like to keep them in the ZODB (not on disk) for ease of administration & installation of the resulting site. However, keeping them in separate python script objects is a pain when editing/updating them. Seems to me it would be useful to have some type of Zope object that would allow definition of multiple functions in a single "file". A. -----Original Message----- From: Jens Vagelpohl [mailto:jens@zope.com] Sent: Thursday, November 07, 2002 7:57 AM To: Andrew Athan Cc: Zope@Zope. Org Subject: Re: [Zope] Utility functions you could put them into a single place, e.g. a folder off your zope root directory, so they don't clutter up the ZMI if that's your concern. thee certainly is no problem creating a bunch of python scripts. jens On Wednesday, Nov 6, 2002, at 23:03 US/Eastern, Andrew Athan wrote:
What is the idiomatic way of expressing utility functions? I.e., python scripts that are meant to be callable by a variety of templates, dtml methods, other python scripts, etc. but which tend to be small, useful, and usually oriented at manipulating data (not generating html).
Creating lots of separate Python (Script) objects seems like overkill, yet defined functions inside such a script don't seem to be easily accessible outside the script object.
E.g.
Script1 ---------
def foo(a): return a[0]
request= container.REQUEST
<blah blah> return container.resultPage()
Script2 -------- <blah> container.Script1.foo(x)
The call in Script2 doesn't work...I'll go read the source for a script object and see if there's an attribute that gives me the access I'm looking for, but I thought I'd ask the list, too.
aathan <Andrew Athan>
Am Donnerstag, 07.11.02, um 14:01 Uhr (Europe/Zurich) schrieb Andrew Athan:
Seems to me it would be useful to have some type of Zope object that would allow definition of multiple functions in a single "file".
Hi Andrew, a ZClass (since you want to edit TTW) with an instance of it at the root level of the Website? Call it "utility", then you can access the script with something like "utility.dothis()" or "here/utility/dothat". Regards, Sascha -- Sascha Welter <mailto:welter@network-ag.com> Network AG Programmer, Sysop, IT-Support, BOFH Ruetistrasse 17 Tel. 01 755 40 20 CH-8952 Schlieren <http://www.network-ag.com> -- Sascha Welter <mailto:welter@network-ag.com> Network AG Programmer, Sysop, IT-Support, BOFH Ruetistrasse 17 Tel. 01 755 40 20 CH-8952 Schlieren <http://www.network-ag.com>
participants (3)
-
Andrew Athan -
Jens Vagelpohl -
Sascha Welter