Skip to content

Instantly share code, notes, and snippets.

@maddievision
Last active December 17, 2015 18:49
Show Gist options
  • Save maddievision/5655536 to your computer and use it in GitHub Desktop.
Save maddievision/5655536 to your computer and use it in GitHub Desktop.
unit conversion
# pip install Pint
from pint import UnitRegistry
ureg = UnitRegistry()
Q_ = ureg.Quantity
def convert(inp):
q,d = inp.split(' to ')
cvt = ""
try:
cvt = "{:0.2f!p~}".format(Q_(q).to(Q_(d)))
except Exception as e:
cvt = "%s" % e
return cvt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment