Skip to content

How to get list of all available units? #1752

Answered by OrangeChannel
engin-can asked this question in Q&A
Discussion options

You must be logged in to vote
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.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by hgrecco
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #1587 on April 26, 2023 23:40.