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); Calculations: How are iterative calculations with variables done correctly in a dtml-Method? like: float x, x=0; x=x+1 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
On Sat, Feb 19, 2000 at 01:12:49PM +0100, 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);
Calculations: How are iterative calculations with variables done correctly in a dtml-Method? like: float x, x=0; x=x+1
Especially the type-conversion puzzles me. I`ve read several Zope-docs, but I have still not figured out how to do this.
You can't create new variables DIRECTLY in DTML. The attitude of the DC people is "if you are creating lots of variables and doing lots of calculations you probably should be doing it in Python." However, you can indirectly create new variables like this: <dtml-call "REQUEST.set('x', 1)"> creates an int called x <dtml-call "REQUEST.set('y', 1.0)"> creates a float called y DTML uses Python variable semantics, so you might want to play around in python a bit to get a feel for the variables:
f = 1 f / 3 0 g = 1.0 g / 3 0.333333333333
In this example, f is automatically typed as an integer, while g is automatically typed as a float. You can override this by using the float and int methods:
float(f) / 3 0.333333333333 int(g) / 3 0
From DTML, you can force x to be created as a float like this: <dtml-call "REQUEST.set('x', _.float(1))"> Notice the _.float call. Some python features are available to DTML through the _ object, for more info check out: http://www.zope.org/Documentation/Guides/DTML-HTML/DTML.5.3.2.3.html
I hope this has helped, if you have any further questions feel free to reply. -- Stephen Pitts smpitts@midsouth.rr.com webmaster - http://www.mschess.org
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
participants (3)
-
Boris Povazay -
Chris McDonough -
Stephen Pitts