I sometimes use the pint
library to display civil engineering calculations.
For these calculations, there are times when I want a quantity displayed a certain way in order to make it clear what the quantity represents. But when using pint
, the units get automatically reduced, making things less clear.
Some examples:
- "moment per unit length": changed from
kip·ft/ft
tokip
- "area per unit length": changed from
in²/in
toin
- "moment of inertia per length": changed from
in⁴/in
toin³
- "slope": changed from
in/in
to unitless
Code illustrating the first example:
>>> import pint
>>> u = pint.UnitRegistry(system='US')
>>> x = 100*u.kip*u.ft/u.ft
>>> f'{x:~P}'
'100.0 kip'
Can I prevent this unit simplification, and get the units to display the way I want?