[Zope] Calculations within a document

Chris McDonough chrism@digicool.com
Sat, 19 Feb 2000 15:24:07 -0500


Boris Povazay wrote:
> 
> Since I am a "Zope-Beginner" I am currently faced with some problems -
> maybe you can help me with these.
> 
> Declarations & type-conversions:
> How are variable-declerations done right within dtml?
> Like: float x;
> or: int x; float y;
> y=float(x);

Boris, it's probably better to create an External Method (or a
PythonMethod) to do more than simple logic in Zope.  An External Method
is a function written in Python.  Python doesn't have compile-time
typing of variables.  You can convert a value from an int to a float,
from a string to an int, etc. after its been declared, but not before. 
You may want to pick up a copy of "Learning Python" by Mark Lutz and
David Ascher (O'Reilly Books) to get an understanding of the language.

If you *really* need to declare variables from within DTML, you can use
the REQUEST.set method like this:

<dtml-call expr="REQUEST.set('myvariable', 'astring')">
or
<dtml-call expr="REQUEST.set('mylist', ['1', '2', '3'])">
ad infinitum.

The syntax of the expressions 'astring', and ['1', '2', '3'] are right
from Python and you'll need to get a hang of Python syntax to use them.

Zopisms
-------
<dtml-call expr="...">
    what follows the expr= is a python expression, is generally
shortened to <dtml-call "..">
<dtml-call name=asdasd>
    what follows the name= is the name of a Zope object, is generally
shortened to <dtml-call asdasd>

 
 
> Calculations:
> How are iterative calculations with variables done correctly in a
> dtml-Method?
> like: float x,
> x=0;
> x=x+1

This logic is better off in an External Method or PythonMethod.  See the
External Method HowTo on Zope.org.

> 
> Especially the type-conversion puzzles me. I`ve read several Zope-docs,
> but I have still not figured out how to do this.
> 
> Thanks a lot in advance for your reply!
> --
> Boris Povazay
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )

-- 
Chris McDonough
Digital Creations, Inc.
Zope - http://www.zope.org