[Zope] Scoping question (Python scripts)
Kirby Urner
pdx4d@teleport.com
Mon, 09 Apr 2001 12:25:08 -0700
At 01:18 PM 4/9/2001 -0400, Evan Simpson wrote:
>From: "Kirby Urner" <pdx4d@teleport.com>
>> So is there something about Python classes that they can't
>> be defined internally to an ordinary function/script?
>
>They cannot usefully be defined in a Script, and Scripts aren't geared
>towards that sort of use. Defining classes is the sort of thing that
>ZClasses and filesystem Products are good for. There are a number of Howtos
>on zope.org that explain how to write simple Products and ZClasses.
>
>What sort of problem are you trying to solve?
At this point I'm prototyping/learning and wanted to generate a
100-digit probably-prime number using Python. Every time you
reload the page, you get a different number, computed on the fly.
Here's the URL (takes a few seconds to load/reload):
http://freezope2.nipltd.net/pdx4d/content/primes/bigprime
The code originally comes from a Python module I wrote outside
of Zope (in 2.1, so I had to change some syntax) with several
function defs. I was treating a Zope script object as a
Python module but have since learned from Martijn Pieters
that it's to be treated as a single function.
Either way, I would rather keep all the code in one place,
versus parsing each little function out to a separate script
file and using context.function(n) calls to tie them together
(I'd done it that way somewhere along the learning curve,
but prefer the current "internal defs" solution, with all
code in one file).
So the solution I have right now uses the nested functions
structure, but I thought maybe I could get around this with
a class structure. Guess not -- unless I go to the next level.
I'm learning in a free Zope hosting system as well as on my
local machine. I'm not sure whether I'll be able to define any
"External Methods" on the free host (sounds like something the
ISP would not allow). I've read 'how-tos' about publishing a
Product but have yet to venture over this bridge (presuming
this test environment will let me).
I'd just read the Zope Book about vaccinating the hippo, and
was trying to hover at that beginner level of simplicity as long
as possible, using nothing more than a basic Python script
object invoked by DTML. It works as is, but I wondered if
this was the optimum way of doing it.
Kirby
>Cheers,
>
>Evan @ digicool