Python 3000 deat !? Is true division ever coming ?

Dan Bishop danb_83 at yahoo.com
Sat Feb 18 03:02:25 EST 2006


Magnus Lycka wrote:
> Gregory Piñero wrote:
> > I knew about that approach.  I just wanted less typing :-(
>
> It's enough to introduce one float in the mix.
> 1.*a/b or float(a)/b if you don't want one more
> multiplication.

That doesn't work if either a or b is a Decimal.  What *could* work is


def is_integer(num):
   return isinstance(num, (int, long))

def divide(a, b):
   if is_integer(a) and is_integer(b):
      return 1.0 * a / b
   else:
      return a / b

But why bother when you could just put "from __future__ import
division" at the top of the file?




More information about the Python-list mailing list