Last active
December 17, 2015 18:49
-
-
Save maddievision/5655536 to your computer and use it in GitHub Desktop.
unit conversion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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