On Tue, Oct 23, 2001 at 11:43:21AM -0700, Ben Ocean wrote:
Hi; I'm new to Python and Zope, but I'm at a loss to understand WHY this doesn't work! I have this line in my dtml code: <span class="top"><img src="images/top" width=<dtml-var "sizeCalc(1008,size)"> height=<dtml-var "sizeCalc(82,size)">></span> *size* is a dtml method and is defined thus: 1 just the number one. sizeCalc(x,y) is an external method and is defined thus:
import string
def sizeCalc(x,y): x = string.atoi(x) y = string.atoi(y)
try this: x = int(x) y = int(y)
I tried the string conversions because the values are being interpreted as strings (already tested that).
Good - you're looking in the right direction. DTML methods return strings.
I get this error:
Error Type: TypeError Error Value: int() can't convert non-string with explicit base
Right. In your dtml page, you called sizeCalc like so: <dtml-var "sizeCalc(82,size)"> The second argument comes from your DTML method, right? That's a string, and that's why you got type errors before. But that first argument is not a string - it's an integer. string.atoi() can only take string arguments. So you've just traded one TypeError for another. You could keep your external method as it is now and call it like this: <dtml-var "sizeCalc('82',size)"> But I suspect you'll be much happier if you make your external method able to deal with both integers and strings, so you don't have to remember this every time you call it. Use python's built-in int() function. (It can also take float arguments - it just chops off anything after the decimal.) -- paul winkler home: http://www.slinkp.com music: http://www.reacharms.com calendars: http://www.calendargalaxy.com