[Zope] expression evaluateion

Michel Pelletier michel@digicool.com
Wed, 15 Mar 2000 22:51:32 -0800


Chien-pin Wang wrote:
> 
> Hi,
> 
>     Zope seems to evaluate expressions in an unconventional way.

Zope doesn't do anything above and beyond what python does.

> Say I have three properties, a=3, b=5, c=7 set in a Folder. In
> a DTML Document I tried to say <dtml-var "a/b*c"> and got result
> 0. The expression was evaluated as a/(b*c) and rounded off. Is
> not the expression supposed to be evaluated as (a/b)*3? The
> result is not correct still if we put it this way:
> <dtml-var "(a/b)*3">. I still got 0 as the result. Did I miss
> anything fundamentally or is this a, bug?

Python rounds integers, quite simply:

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> 1/2
0
>>> 3/5*7
0
>>> (3/5)*7
0
>>> 3/(5*7)
0
>>> 

integers as input gives an integer as output.  Obviously there are two
schools of thought on this.  If you want a floating point number, use
'float()' (or in DTML, _.float())

>>> float(1)/float(2)
0.5
>>> 

-Michel