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?
--
http://mail.python.org/mailman/listinfo/python-list