[SciPy-user] Python number handling?

Robert Kern rkern at ucsd.edu
Wed Aug 10 19:57:46 EDT 2005


Robert Kern wrote:
> Lance Boyle wrote:
> 
>> Yes. But what about a / b given that a and b are dynamically typed?
> 
> It's handled by their types' coercion rules and __truediv__ definitions 
> (or __div__ if __truediv__ isn't defined).

Sorry, that parenthetical is incorrect.

 From http://docs.python.org/ref/numeric-types.html :

"""
__div__(self, other)
__truediv__(self, other)
     The division operator (/) is implemented by these methods. The 
__truediv__() method is used when __future__.division is in effect, 
otherwise __div__() is used. If only one of these two methods is 
defined, the object will not support division in the alternate context; 
TypeError will be raised instead."""

-- 
Robert Kern
rkern at ucsd.edu

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter




More information about the SciPy-User mailing list