Commit bfc1b529 authored by Peter Eastman's avatar Peter Eastman
Browse files

Define both __div__ and __truediv__ to work on all Python versions

parent d648613b
...@@ -383,6 +383,8 @@ class Quantity(object): ...@@ -383,6 +383,8 @@ class Quantity(object):
return self * pow(other, -1.0) return self * pow(other, -1.0)
# return Quantity(self._value / other, self.unit) # return Quantity(self._value / other, self.unit)
__div__ = __truediv__
def __rtruediv__(self, other): def __rtruediv__(self, other):
"""Divide a scalar by a quantity. """Divide a scalar by a quantity.
...@@ -398,6 +400,8 @@ class Quantity(object): ...@@ -398,6 +400,8 @@ class Quantity(object):
return other * pow(self, -1.0) return other * pow(self, -1.0)
# return Quantity(other / self._value, pow(self.unit, -1.0)) # return Quantity(other / self._value, pow(self.unit, -1.0))
__rdiv__ = __rtruediv__
def __pow__(self, exponent): def __pow__(self, exponent):
"""Raise a Quantity to a power. """Raise a Quantity to a power.
......
...@@ -187,6 +187,8 @@ class Unit(object): ...@@ -187,6 +187,8 @@ class Unit(object):
""" """
return self * pow(other, -1) return self * pow(other, -1)
__div__ = __truediv__
# def __rtruediv__(self, other): # def __rtruediv__(self, other):
# Because rtruediv returns a Quantity, look in quantity.py for definition of Unit.__rtruediv__ # Because rtruediv returns a Quantity, look in quantity.py for definition of Unit.__rtruediv__
......
...@@ -44,6 +44,7 @@ def _unit_class_rdiv(self, other): ...@@ -44,6 +44,7 @@ def _unit_class_rdiv(self, other):
return Quantity(value, unit).reduce_unit(self) return Quantity(value, unit).reduce_unit(self)
Unit.__rtruediv__ = _unit_class_rdiv Unit.__rtruediv__ = _unit_class_rdiv
Unit.__rdiv__ = _unit_class_rdiv
def _unit_class_mul(self, other): def _unit_class_mul(self, other):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment