[Zope] Python Classes and Zope.
Dario Lopez-Kästen
dario at ita.chalmers.se
Thu Dec 1 12:13:36 EST 2005
Andreas Jung wrote:
>
>
> --On 1. Dezember 2005 13:46:55 -0200 Fernando Lujan
> <fernando.lujan at terra.com.br> wrote:
>
>> There's a way to use a Python class inside zope?
>>
>> For instance, if I create the class:
>>
>> class MyClass:
>> "A simple example class"
>> i = 12345
>> def f(self):
>> return 'hello world'
>>
>> Can I invoke the following code inside a Python Script?
>>
>> x = MyClass()
>> x.f()
>>
>
> PythonScripts are for *scripting* not for implementing complex
> logic and for programming tasks that require classes. PythonScripts
> don't provide full Python functionality that why were are talking of
> *Restriced Python*. Consider writing your functionality as Python product.
all moral lessons aside, there are several use cases where access to
*objects*, passed to zope2 from external packages and modules, is desirable.
Most, if not all examples, out there assume that the external
packages/modules/classes can freely be converted to Zope-classes.
Now, assuming that I have not missed something fundamental, the problem
the way I see it, is that when my Product recieves an object from the
non-zope code, the object does not know anything about Zope, it is just
a happy Python-object.
But in order to even display it in a zpt I must transmogrify it into a
special zope-object, and *that* is not so easy as I have discovered.
In my case I am not so interested in importing the moduels or classes
into a Script(Python) - I have allready passed the objects in question
thtough my product, but still I get some "Zope Does Not Allow That" error.
So far I have not had any success with anything else than writing
special methods in my Classes that converts the objects to dictionaries
before passing them to the zpt or Script(Python) in question.
But that feels like a very awkward way of doing things, and it makeas it
*very* difficult for Zope to be a nice player with non-zope objects.
My 2 €-cents worth.
/dario
--
-- -------------------------------------------------------------------
Dario Lopez-Kästen, IT Systems & Services Chalmers University of Tech.
Lyrics applied to programming & application design:
"emancipate yourself from mental slavery" - redemption song, b. marley
More information about the Zope
mailing list