I was trying the following code,
from pint import UnitRegistry
ureg = UnitRegistry()
Q_ = ureg.Quantity
class Simple:
@ureg.wraps(None, (None, None, 'm**3'), True)
def __init__(self, a, b):
self.a = a
self.b = b
def calculate(self):
return self.a*self.b
if __name__ == "__main__":
c = Simple(2, Q_(20, 'm**3')).calculate()
print c
which gives the output,
40.0
This is a float type. Is there a way to instead automatically output a pint Quantity object with magnitude and correct units, i.e. 40.0 m**3?
Thanks