Etherium unit conversation and arithmetic library
pip install -u etherunit>>>frometherunitimportEther, Gwei, Wei, EYou can create a new quatity like this
>>>Ether(".05")
0.05ether>>>Gwei(".05")
0.05gwei>>>Wei("5")
5weiOr you can use the helper function E() to create a new quantity
>>>E(".05 eth")
0.05ether>>>E(".05 gwei")
0.05gwei>>>E("5 wei")
5weiDifferent quatities can be added together without any problems
>>>E(".05 eth") +E("2 gwei") ==E("0.050000002 eth")
TrueThis also applies for subtraction
>>>E(".05 eth") -E("2 gwei") ==E("0.049999998 eth")
TrueYou can also multiply quanities with other integers
>>>E(".05 eth") *20.1ether... but not with other quatities
>>>E(".05 eth") *E("2 gwei") # type: ignoreAssertionError: 2gweiisnotanintegerYou also can't multiply quatities with other integers, like floats. Why? Because it can result with fractional wei, which is not allowed
>>>E(".05 eth") *1.5AssertionError: 1.5isnotanintegerYou can divide quatities with other integers, the result is always a quatity
>>>E(".05 eth") /20.025etherAnd you can divide quatities with other quatities, the result is always an integer
>>>E("10 eth") /E("3 eth")
3You can find the remainder of a division with mod operator (%)
>>>E("10 eth") %E("3 eth")
1etherYou can also use divmod() to get both the quotient and the remainder
>>>divmod(E("10 eth"), E("3 eth"))
(3, 1ether)You can convert a quatity to another quatity, though it's not necessary for arithmetic operations
>>>E("10 eth").gwei10000000000gwei>>>E("10 eth").wei10000000000000000000wei>>> (E("10 eth") %E("3 eth")).wei1000000000000000000wei>>>E("10 eth").wei.eth.eth.eth.eth.gwei.wei.wei.wei# :D10000000000000000000wei