Dario Lopez-Kästen wrote:

Andreas Jung wrote:

--On 1. Dezember 2005 13:46:55 -0200 Fernando Lujan <[EMAIL PROTECTED]> 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()

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.


You need to call InitializeClass on your object, and that's it.

cf http://www.upfrontsystems.co.za/courses/zope/ch04.html

under "Zopifying our Python classes"

Zope maillist  -  Zope@zope.org
**   No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to