How to get list of all available units? #1752
-
Hey guys, how can I programmatically get a list of all available units? |
Beta Was this translation helpful? Give feedback.
Answered by
OrangeChannel
Sep 30, 2022
Replies: 1 comment
-
import pint
ureg = pint.UnitRegistry()
list_of_units = set()
for x in dir(ureg):
try:
if isinstance((u := getattr(ureg, x)), pint.Unit):
list_of_units.add(u)
except:
pass
list_of_units = list(list_of_units) Unless there's some builtin way I'm not aware of. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
hgrecco
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unless there's some builtin way I'm not aware of.