[Zope] Passing data to/from Python

Ken Kinder kkinder@messagemedia.com
Sat, 25 Mar 2000 22:57:41 -0700


> 
> 
> 1. It seems that the only way to establish a DB connection is
> through Gadfly. There are warnings everywhere that Gadfly is
> inefficient. Therefore, I want to use ODBC (ODBC.Windows), like I
> did before. How?

First of all, someone needs to let you know that data should never be 
stored in an Excel file. Anyway, what you would do is use the Zope ODBC 
database adapter. The Gadfly one is the only one installed by default, 
but others are availible at zope.org

You really should be storing that in a relational database though. 
Speaking for years of database experience, Excel is never a good place 
to keep things.
> 
> 
> 
> 2. I might eventually need to do complex calculations on the
> retrieved data, so I would prefer using Python code in an
> external method, rather than a DTML method. In order to get Zope
> to accept the line "import ODBC.Windows", I had to copy the ODBC
> and DateTime directories from my regular Python installation
> (PYTHON/lib) to ZOPE/bin/lib. But then, when I try running the
> script, I get one of the following problems:
> 
>    a. If I go through authentification, the script runs, but I
>    cannot establish the connection to the database.

This isn't really a Zope issue. It's a bug in your script or the serveor 
or something to that effect.
> 
> 
> 
>    b. If I type in the URL of my search page directly, without
>    authentification, I get a Zope error: "initialization of
>    module mxODBC failed
>    (exceptions.AttributeError:mxDateTimeAPI)".
> 
> Is my ODBC.Windows installation wrong, or do I have a more
> fundamental problem?

Ask those in the ODBC.Windows mailing list; this is not a Zope issue.

You might consider though, not using so many external methods and 
whether writing packages - they are more powerful and can be more 
powerful. External Methods are usually for quick one-timers.
> 
> 
> 
> 3. What if my Python function in my external method wants to
> return information to my DTML method? For instance, how do I
> return a Python list, and what do I do in my DTML method to
> process it (e.g., output a line for every member of the list)?

I beleive you can do just that - return it as a list, and use it like 
this inside DTML

<dtml-in externalmethodid>
  ...
</dtml-in>
> 
> 
> 
> 4. The way I call my Python function now is through the > tag, where "search" is the external method ID. The form has a field 
> called "name", and my Python function has an argument also called 
> "name", and so it recuperates the string that was entered in the 
> "name" field. Can I pass the "name" as an argument to a DTML method
> 
I'll have to pass on this question to someone who is more experienced.

> 
> 
> 
> If these questions have answers, I would really appreciate them. 
> Otherwise, if I'm completely off-base (for instance, if I'm thinking 
> in Python terms and not in Zope terms), please point me in the right 
> direction!
> 
> 

Hang in there. Learning to do this kind of thing in ZOPE is hard - I 
know because I'm trying to do it myself.