[Zope] Float object not callable (newbie question)

Tino Wildenhain tino at wildenhain.de
Sat May 14 14:50:10 EDT 2005


Am Freitag, den 13.05.2005, 16:06 +0100 schrieb Paul Hendrick:
> hi all,
> I'm trying to write a simple app which takes a name, bank balance,
> interest rate and returns the balance once 1 years interest has been
> added. I'm getting the error that float object is not callable. 
> i can't figure out where i'm going wrong :S
> 
> my code is below(getDetails, showDetails,doStuff.py), thanks for any
> input!
> paul.
> 
> <html>
> <body>
> 
> <form action="showDetails" method=post>
>  <input name="name:str"> NAME<br>
>  <input name="balance:float"> BALANCE<br>
>  <input name="interestRate:float"> INTEREST RATE<br>
>  <input type="submit" value="calculate">
> </form>
> 
> </body>
> </html>

This seems ok.
> ------------------
> <html>
> <body>
> 
> <span tal:define="name request/name;
>                   balance request/balance;
>                   rate request/interestRate">
>  <span tal:content="python: here.doStuff(name,balance,rate)"></span>
> </span>
> 
> </body>
> </html>

Why this? 1) your python script can read request just fine. No
             need for clumsy code in ZPT
          2) your code below returns a list, so all you get 
             is the string representation of a list. Works
             but does not look so fine ;)

> --------------
> years = 1
> newBal = balance( balance*(rate*years))

You call balance as function by using ().
Try your function in the interactive interpreter if 
unsure, e.g. 

balance = 5000
rate = 8 # in percent I assume? You should state that in the form
years = 4

newbalance = balance * (1+rate/100.0) ** years

if you output newbalance, you will see if it does what you want.

if you transfer it into the python script,
replace the assignments with 

balance = context.REQUEST.get("balance",0)
rate = context.REQUEST.get("rate",0)
years = context.REQUEST.get("years",0)

and 

return newbalance

at the end.
(You can also skip the variable and return the
 result of the expression directly)


I'd point the form to itself and make
the output just below it.

<span tal:content="here/doStuff" />

thats all.





More information about the Zope mailing list