[Python-Dev] Numeric conversions
David Abrahams
David Abrahams" <david.abrahams@rcn.com
Sun, 2 Jun 2002 11:58:51 -0400
From: "Aahz" <aahz@pythoncraft.com>
> On Sun, Jun 02, 2002, David Abrahams wrote:
> >
> > The following small program is giving me some unexpected results with
> > Python 2.2.1:
> >
> > class Int(object):
> > def __int__(self): return 10
> >
> > class Float(object):
> > def __float__(self): return 10.0
> >
> > ----- results ------
> >
> > int(Int) 10
> > int(Float) TypeError: object can't be converted to int
>
> Um. I'm confuzzled. Float doesn't have an __int__ method; why do you
> expect it to work?
I don't. as I wrote below that:
*** OK, int() seems to work as expected
Each item beginning with '***' is meant to refer to the group of 4 lines
above.