[Zope] VERY Confused!
Paul Winkler
slinkp23@yahoo.com
Tue, 23 Oct 2001 17:37:11 -0400
On Tue, Oct 23, 2001 at 09:42:23PM +0100, seb bacon wrote:
> > Hmm. Tested *both* variables using type and *both* returned string.
AFAIK that can't be true with the examples you posted. Are you sure
you didn't change the <dtml-var> stuff since you checked the types?
> > I forgot to post that I *had* tried that. This is the error:
> > Error Type: AttributeError
> > Error Value: __int__
> >
> > I'm even more confused than before and concerned that there might be
> > something wrong with my installation at this point.
>
> Unlikely ;-)
>
> I just tried the code to make sure, and it works for me; the number
> being passed as the first argument *is* an int.
>
> The AttributeError suggests you're passing an object rather than a
> string or an int to the script.
Right. Try this at the python prompt (the BEST way to learn the zen of
python!):
$ python
Python 1.5.2 (#1, Aug 25 2000, 09:33:37) [GCC 2.96 20000731
(experimental)] on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> class Foo:
... pass
...
>>> int(1)
1
>>> int(1.0)
1
>>> int("1")
1
>>> int( Foo() )
Traceback (innermost last):
File "<stdin>", line 1, in ?
AttributeError: __int__
When int() gets an object that isn't an integer, a float, or a string,
it looks to see if that object provides an __int__() method and calls
that to convert it to an integer. If the object doesn't provide such a
method, you get the AttributeError.
> I feel sure you have somehow got your type checking wrong when
> you were debugging, since strings and ints would never give this
> AttributeError, and the first argument, 2008, is definitely an int.
>
> Perhaps you have a namespace clash with an object elsewhere in your
> acquisition path, also called 'size'? Try renaming the 'size' method.
Wait a minute - if "size" is a method, you need to call it, not pass
it! Python doesn't automatically call methods the way Zope does.
It could be you're passing the method to your external method, instead of calling the size method and passing the RESULT to your external method.
Without quotes it gets automagically called: <dtml-var size>
With quotes, it's python and you need parentheses to
call it: <dtml-var "size()">
--
paul winkler
home: http://www.slinkp.com
music: http://www.reacharms.com
calendars: http://www.calendargalaxy.com