[Python-Dev] Numeric conversions
Aahz
aahz@pythoncraft.com
Sun, 2 Jun 2002 11:56:33 -0400
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?
--
Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/
"In the end, outside of spy agencies, people are far too trusting and
willing to help." --Ira Winkler